📄 usebeantag.java
字号:
package org.it315;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class UseBeanTag extends TagSupport
{
private String name;
private String type;
private String scope;
private int iScope;
public void setName(String name)
{
this.name = name;
}
public void setType(String type)
{
this.type = type;
}
public void setScope(String scope)
{
this.scope = scope;
}
public int doStartTag() throws JspException
{
if("page".equals(scope))
{
iScope = pageContext.PAGE_SCOPE;
}
else if("request".equals(scope))
{
iScope = pageContext.REQUEST_SCOPE;
}
else if("session".equals(scope))
{
iScope = pageContext.SESSION_SCOPE;
}
else if("application".equals(scope))
{
iScope = pageContext.APPLICATION_SCOPE;
}
try
{
Object obj = Class.forName(type).newInstance();//实例化引入的类
pageContext.setAttribute(name, obj, iScope);
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
return EVAL_BODY_INCLUDE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -