?? httpparamtag.java
字號(hào):
/*
* Created on 2004-2-19 By Liudong
*/
package jdlog.util.tags;
import java.lang.reflect.Constructor;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
/**
* 用戶處于請(qǐng)求參數(shù)的標(biāo)簽庫(直接生成指定類型的變量)
* @author Liudong
*/
public class HttpParamTag extends TagSupport {
String id = null; //變量名稱
String type = String.class.getName(); //參數(shù)類型(默認(rèn)是字符串類型)
String name = null; //參數(shù)名
String value = null; //如果沒有指定參數(shù)則使用該缺省值,該類型必須具有一個(gè)帶一個(gè)字符串參數(shù)的構(gòu)造子
public int doStartTag() throws JspException {
try {
Class cls = Class.forName(type);
Constructor con = cls.getConstructor(new Class[] {String.class});
String paramValue = pageContext.getRequest().getParameter(name);
if(paramValue==null)
paramValue = value;
Object obj = con.newInstance(new Object[] {paramValue});
pageContext.setAttribute(id, obj);
}catch(Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -