public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) throws IOException, ServletException { HttpServletRequest request=(HttpServletRequest)arg0; HttpServletResponse response=(HttpServletResponse)arg1; if(request.getSession().getAttribute("username")!=null){ chain.doFilter(arg0, arg1); }else{ response.sendRedirect("/index.jsp");; } }
以上是拦截器代码
以下是xml配置
<servlet> <servlet-name>LoginFilter</servlet-name> <servlet-class>Servlet.login</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginFilter</servlet-name> <url-pattern>/Servlet/login</url-pattern> </servlet-mapping> <filter> <filter-name>LoginFilter</filter-name> <filter-class>filter.longin</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>/success.jsp</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping>
你这里应该是有一个明显错误,多个类映射到同一名字“LoginFilter"