1 package example.taglib; 2 3 import javax.servlet.jsp.*; 4 import javax.servlet.jsp.tagext.*; 5 import java.io.*; 6 7 public class MessageTag extends BodyTagSupport { 8 9 16 private String _attrTitle; 17 18 24 private String _title; 25 private StringBuffer _msg; 26 27 public void setTitle(String title) 28 { 29 _attrTitle = title; 31 } 32 33 public int doStartTag() 34 throws JspException 35 { 36 init(); 38 39 return EVAL_BODY_BUFFERED; 40 } 41 42 public int doEndTag() 43 throws JspException 44 { 45 init(); 47 48 try { 49 JspWriter out = pageContext.getOut(); 51 out.println("<p>"); 52 out.println("<table border=1>"); 53 out.println("<tr><td>"); 54 out.println("instance: " + this); 55 out.println("<tr><td>"); 56 out.println(_title); 57 out.println("<tr><td>"); 58 out.println(_msg.toString()); 59 out.println("</table>"); 60 61 } catch (Exception ex) { 62 throw new JspException(ex); 63 } 64 65 return EVAL_PAGE; 66 } 67 68 72 protected void init() 73 { 74 _title = _attrTitle; 76 if (_title == null) 77 _title = "Default Title"; 78 79 _msg = new StringBuffer (); 81 82 } 83 84 88 void addToMessage(String text) 89 throws JspException 90 { 91 _msg.append(text); 92 _msg.append("<br>"); 93 } 94 } 95 96 | Popular Tags |