1 16 17 package org.apache.taglibs.log; 18 19 import java.util.Enumeration ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.PageContext ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 public class DumpTag extends TagSupport { 26 27 private int scope; 28 29 30 public void setScope(String sc) throws JspException { 31 if (sc.equalsIgnoreCase("session")) { 32 this.scope = PageContext.SESSION_SCOPE; 33 } 34 else if (sc.equalsIgnoreCase("request")) { 35 this.scope = PageContext.REQUEST_SCOPE; 36 } 37 else if (sc.equalsIgnoreCase("application")) { 38 this.scope = PageContext.APPLICATION_SCOPE; 39 } 40 else if (sc.equalsIgnoreCase("page")) { 41 this.scope = PageContext.PAGE_SCOPE; 42 } 43 else { 44 throw new JspException ( 45 "Scope must be page, request, session or application." 46 ); 47 } 48 } 49 50 public int doEndTag() throws JspException { 51 try { 52 Enumeration names = pageContext.getAttributeNamesInScope(scope); 53 pageContext.getOut().write("<dl>"); 54 while(names.hasMoreElements()) { 55 String name = (String ) names.nextElement(); 56 Object value = pageContext.getAttribute(name, scope); 57 58 pageContext.getOut().write("<dt><code>"+name+"</code></dt>"); 59 pageContext.getOut().write("<dd><code>"+value+"</code></dd>"); 60 } 61 pageContext.getOut().write("</dl>"); 62 } 63 catch (Exception e) { 64 throw new JspException ("Exception: "+e.getMessage()); 65 } 66 return EVAL_PAGE; 67 } 68 } 69 | Popular Tags |