写了一个过滤器 所有路径都找不到了
没写之前还好好的 用过滤器写的检测用户是否登录 结果所有的网页都打不开了(报的是404路径错误)
地址
http://localhost:8000/hospital/web/login.jsp
下面是我在web.xml中配置的(把这段注释掉以后就可以打开网页了)
<filter> <filter-name>checkLogin</filter-name> <filter-class>hospital.filters.LoginFilter</filter-class> <init-param> <param-name>redirectURL</param-name> <param-value>/web/login.jsp</param-value> </init-param> <init-param> <param-name>checkSessionKey</param-name> <param-value>loginName</param-value> </init-param> <init-param> <param-name>notCheckURLList</param-name> <param-value>/web/LoginServlet;/web/login.jsp</param-value> </init-param> </filter> <filter-mapping> <filter-name>checkLogin</filter-name> <url-pattern>/web/*</url-pattern> </filter-mapping>
package hospital.filters;import java.io.IOException;import java.util.ArrayList;import java.util.List;import java.util.StringTokenizer;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{ protected FilterConfig filterConfig = null; private String redirectURL = null; private List notCheckURLList = new ArrayList(); private String sessionKey = null; public void destroy() { System.out.println("destroy"); notCheckURLList.clear(); } public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { System.out.println("doFilter"); HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; HttpSession session = request.getSession(); if (sessionKey == null) { filterChain.doFilter(request, response); return; } if ((!checkRequestURIIntNotFilterList(request)) && session.getAttribute(sessionKey) == null) { response.sendRedirect(request.getContextPath() + redirectURL); return; } filterChain.doFilter(servletRequest, servletResponse); } public void init(FilterConfig arg0) throws ServletException { System.out.println("init"); this.filterConfig = filterConfig; redirectURL = filterConfig.getInitParameter("redirectURL"); sessionKey = filterConfig.getInitParameter("checkSessionKey"); String notCheckURLListStr = filterConfig .getInitParameter("notCheckURLList"); if (notCheckURLListStr != null) { StringTokenizer st = new StringTokenizer(notCheckURLListStr, ";"); notCheckURLList.clear(); while (st.hasMoreTokens()) { notCheckURLList.add(st.nextToken()); } } } private boolean checkRequestURIIntNotFilterList(HttpServletRequest request) { String uri = request.getServletPath() + (request.getPathInfo() == null ? "" : request.getPathInfo()); return notCheckURLList.contains(uri); } }