KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > util > tags > HttpParamTag


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.util.tags;
17
18 import java.lang.reflect.Constructor JavaDoc;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 /**
24  * 用户处于请求参数的标签库(直接生成指定类型的变量)
25  * @author Liudong
26  */

27 public class HttpParamTag extends TagSupport JavaDoc {
28     
29     String JavaDoc id = null; //变量名称
30
String JavaDoc type = String JavaDoc.class.getName(); //参数类型(默认是字符串类型)
31
String JavaDoc name = null; //参数名
32
String JavaDoc value = null; //如果没有指定参数则使用该缺省值,该类型必须具有一个带一个字符串参数的构造子
33

34     public int doStartTag() throws JspException JavaDoc {
35         try {
36             Class JavaDoc cls = Class.forName(type);
37             Constructor JavaDoc con = cls.getConstructor(new Class JavaDoc[] {String JavaDoc.class});
38             String JavaDoc paramValue = pageContext.getRequest().getParameter(name);
39             if(paramValue==null)
40                 paramValue = value;
41             Object JavaDoc obj = con.newInstance(new Object JavaDoc[] {paramValue});
42             pageContext.setAttribute(id, obj);
43         }catch(Exception JavaDoc e) {
44             throw new JspException JavaDoc(e);
45         }
46         return SKIP_BODY;
47     }
48     public String JavaDoc getId() {
49         return id;
50     }
51     public void setId(String JavaDoc id) {
52         this.id = id;
53     }
54     public String JavaDoc getType() {
55         return type;
56     }
57     public void setType(String JavaDoc type) {
58         this.type = type;
59     }
60     public String JavaDoc getName() {
61         return name;
62     }
63     public void setName(String JavaDoc name) {
64         this.name = name;
65     }
66     public String JavaDoc getValue() {
67         return value;
68     }
69     public void setValue(String JavaDoc value) {
70         this.value = value;
71     }
72 }
73
Popular Tags