📄 nametag.java
字号:
package tagext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import java.io.IOException;
import javax.servlet.http.HttpSession;
public class NameTag implements Tag
{
private PageContext context=null;
private Tag parent=null;
private String userName=null;
public void setPageContext(PageContext context)
{
this.context=context;
}
public void setParent(Tag parent)
{
this.parent=parent;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public Tag getParent()
{
return this.parent;
}
public int doStartTag()throws JspException
{
JspWriter out=this.context.getOut();
HttpSession session= this.context.getSession();
String user=(String)session.getAttribute(userName);
try
{
out.print(user);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
return this.SKIP_BODY;
}
public int doEndTag()throws JspException
{
return this.EVAL_PAGE;
}
public void release()
{
this.context=null;
this.parent=null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -