实现步骤:
1、创建一个过滤器操作类。
2、修改web.xml文件,在web.xml文件中配置过滤器的内容
3、创建相应的Jsp页面。
具体代码
创建一个过滤器操作类
package com.caokaiyuan.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class LoginFilter implements Filter
{
private FilterConfig config;
@Override
public void destroy()
{
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest)arg0;
HttpServletResponse response = (HttpServletResponse)arg1;
HttpSession session = request.getSession();
//获得不过滤的页面或Servlet
String noLoginPaths = config.getInitParameter("noFilter");
//分割noLoginPaths字符串,获得不过滤的每一个内容
if (noLoginPaths != null)
{
String strArray[] = noLoginPaths.split(";");
for (int i=0; i<strArray.length; i++)
{
if (strArray[i]==null || "".equals(strArray[i]))
continue;
if (request.getRequestURI().indexOf(strArray[i])!=-1)