问答详情
源自:6-1 登录案例

请问,我这边的过滤器不起作用是什么情况。不输入用户名和密码就跳到失败页面,不像老师那样

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>


提问者:慕粉1473922411 2018-10-11 10:51

个回答

  • 慕姐2893314
    2018-10-16 10:39:26
    已采纳

    你这里应该是有一个明显错误,多个类映射到同一名字“LoginFilter"