📄 validatetag.java
字号:
package com.wrox.secure;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
public class ValidateTag extends TagSupport
{
private String errorPage;
private String securePage;
private String password;
private String username;
private UserList database = new UserList();
public void setSecurePage(String page)
{
this.securePage = page;
}
public void setErrorPage(String page)
{
this.errorPage = page;
}
public void setPassword(String password)
{
this.password = password;
}
public void setUsername(String username)
{
this.username = username;
}
public int doEndTag() throws JspException
{
HttpSession thisSession = pageContext.getSession();
User user = new User(this.username, this.password);
if(database.isValidUser(user))
{
thisSession.setAttribute("user", this.username);
try
{
pageContext.forward(this.securePage);
return this.SKIP_BODY;
}
catch(Exception ex)
{
throw new JspException(ex.getMessage());
}
}
else
{
try
{
pageContext.forward(this.errorPage);
}
catch(Exception ex)
{
throw new JspException(ex.getMessage());
}
}
return EVAL_PAGE;
}
public void release()
{
this.securePage = null;
this.username = null;
this.password = null;
this.errorPage = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -