<filter>
<filter
<filter
limas
</filter
<init
<param
<param
</init
</filter>
<filter
<filter
<url
</filter
<filter
<init
<filter
package limas
import java
import javax
import javax
import javax
import javax
import javax
import limas
import javax
import javax
import org
import nstants
/**
* Filter implementation for user authentication
* @author tyrone * @version $Id: AuthenticationFilter
*/public class AuthenticationFilter implements Filter{
/**
* filterConfig will store the reference of FilterConfig
*/ private FilterConfig filterConfig;
private String onErrorUrl;
/**
* store the reference of the FilterConfig
* @param config FilterConfig object
* @throws ServletException
*/ public void init(FilterConfig config) throws ServletException
{//獲得驗證失敗forward地址
filterConfig = config;
onErrorUrl=filterConfig
if (onErrorUrl==null ||
onErrorUrl=
}
}
/**
* User Authentication is done
* control is transferred to logon URI
* @param ServletRequest Request
* @param ServletRequest Response
* @param FilterChain Filter Chain
* @throws ServletException
*/ public void doFilter(ServletRequest request
throws IOException
{
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse=(HttpServletResponse)response;
// Current session
HttpSession httpSession = ();
//Session裡是否有用戶信息
if ((Constants
{
ActionErrors errors=new ActionErrors();
errors
new ActionError(
(Globals
//沒有
(onErrorUrl)
}else//成果過濾Action結束
next
}
/**
* destroy() method is called by the servlet container
*/ public void destroy()
{
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28400.html