1 14 15 package com.jdon.strutsutil.taglib; 16 17 import java.io.IOException ; 18 19 import javax.servlet.http.HttpServletResponse ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.JspWriter ; 22 import javax.servlet.jsp.tagext.BodyTagSupport ; 23 24 public class NextTag extends BodyTagSupport { 25 26 private boolean disp = false; 27 28 private String name = null; 29 30 public String getName() { 31 return name; 32 } 33 34 public void setName(String name) { 35 this.name = name; 36 } 37 38 public int doStartTag() throws JspException { 39 40 String dispStrs = (String ) pageContext.getAttribute(MPageTag.DISP); 41 if ((dispStrs != null) && (!dispStrs.equals(""))) { 42 if (dispStrs.equals("on")) 43 disp = true; 44 else if (dispStrs.equals("off")) 45 disp = false; 46 } 47 48 String startStrs = (String ) pageContext.getAttribute(MPageTag.START); 49 int start = Integer.parseInt(startStrs); 50 51 String url = (String ) pageContext.getAttribute(MPageTag.URLNAME); 52 53 String countStrs = (String ) pageContext.getAttribute(MPageTag.COUNT); 54 int count = Integer.parseInt(countStrs); 55 56 String allCountStrs = (String ) pageContext.getAttribute(MPageTag.ALLCOUNT); 57 int allCount = Integer.parseInt(allCountStrs); 58 59 60 StringBuffer buf = new StringBuffer (100); 61 62 if ((allCount > (start + count)) ) { 63 buf.append("<a HREF=\""); 64 buf.append(url); 65 buf.append("&start="); 66 buf.append((start + count)); 67 buf.append("\" >"); 68 if (name != null) 69 buf.append(name); 70 } else 71 buf.append(""); 72 73 output(buf.toString()); 74 75 return (EVAL_BODY_INCLUDE); 76 77 } 78 79 85 public int doEndTag() throws JspException { 86 output("</a>"); 87 return (EVAL_PAGE); 88 89 } 90 91 private void output(String s) throws JspException { 92 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 93 JspWriter writer = pageContext.getOut(); 94 try { 95 if (disp) 96 writer.print(s); 97 } catch (IOException e) { 98 throw new JspException ("NextTag error"); 99 } 100 101 } 102 103 104 public void release() { 105 super.release(); 106 disp = false; 107 name = null; 108 109 } 110 111 112 113 } 114 | Popular Tags |