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 PrevTag extends BodyTagSupport { 25 26 private boolean disp = false; 27 28 private String name = null; 29 30 private String text = null; 31 32 public String getName() { 33 return name; 34 } 35 36 public void setName(String name) { 37 this.name = name; 38 } 39 40 public int doStartTag() throws JspException { 41 42 String dispStrs = (String ) pageContext.getAttribute(MPageTag.DISP); 43 if ((dispStrs != null) && (!dispStrs.equals(""))) { 44 if (dispStrs.equals("on")) 45 disp = true; 46 else if (dispStrs.equals("off")) 47 disp = false; 48 } 49 50 String startStrs = (String ) pageContext.getAttribute(MPageTag.START); 51 int start = Integer.parseInt(startStrs); 52 String url = (String ) pageContext.getAttribute(MPageTag.URLNAME); 53 String countStrs = (String ) pageContext.getAttribute(MPageTag.COUNT); 54 int count = Integer.parseInt(countStrs); 55 56 StringBuffer buf = new StringBuffer (100); 57 if (start > 0) { 59 60 buf.append("<a HREF=\""); 61 buf.append(url); 62 buf.append("&start="); 63 buf.append((start - count)); 64 buf.append("\" >"); 65 if (name != null) 66 buf.append(name); 67 } else 68 buf.append(""); 69 70 output(buf.toString()); 71 72 return (EVAL_BODY_INCLUDE); 73 74 } 75 76 82 public int doEndTag() throws JspException { 83 output("</a>"); 84 85 return (EVAL_PAGE); 86 87 } 88 89 private void output(String s) throws JspException { 90 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 91 JspWriter writer = pageContext.getOut(); 92 try { 93 if (disp) 94 writer.print(s); 95 } catch (IOException e) { 96 throw new JspException ("NextTag error"); 97 } 98 99 } 100 101 public void release() { 102 103 super.release(); 104 105 disp = false; 106 name = null; 107 108 } 109 110 } 111 | Popular Tags |