1 16 package dlog4j.util.tags; 17 18 import java.lang.reflect.Constructor ; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.TagSupport ; 22 23 27 public class HttpParamTag extends TagSupport { 28 29 String id = null; String type = String .class.getName(); String name = null; String value = null; 34 public int doStartTag() throws JspException { 35 try { 36 Class cls = Class.forName(type); 37 Constructor con = cls.getConstructor(new Class [] {String .class}); 38 String paramValue = pageContext.getRequest().getParameter(name); 39 if(paramValue==null) 40 paramValue = value; 41 Object obj = con.newInstance(new Object [] {paramValue}); 42 pageContext.setAttribute(id, obj); 43 }catch(Exception e) { 44 throw new JspException (e); 45 } 46 return SKIP_BODY; 47 } 48 public String getId() { 49 return id; 50 } 51 public void setId(String id) { 52 this.id = id; 53 } 54 public String getType() { 55 return type; 56 } 57 public void setType(String type) { 58 this.type = type; 59 } 60 public String getName() { 61 return name; 62 } 63 public void setName(String name) { 64 this.name = name; 65 } 66 public String getValue() { 67 return value; 68 } 69 public void setValue(String value) { 70 this.value = value; 71 } 72 } 73 | Popular Tags |