当前位置: 代码迷 >> Java Web开发 >> TOMCAT过滤器不能通常过滤 急
  详细解决方案

TOMCAT过滤器不能通常过滤 急

热度:21   发布时间:2016-04-17 16:45:15.0
TOMCAT过滤器不能正常过滤 急!!!!
class:

public   class   SignonFilter   implements   Filter   {
protected   FilterConfig   filterConfig;
// 过滤处理
public   void   doFilter(ServletRequest   req,   ServletResponse   res,
FilterChain   chain)   throws   IOException,   ServletException   {

HttpServletRequest   hreq   =(HttpServletRequest)req;
HttpServletResponse   hres   =   (HttpServletResponse)res;
HttpSession   session   =   hreq.getSession();
String   isLogin   = " ";
isLogin   =   (String)   session.getAttribute( "userName ");

//如果已经登陆
if(isLogin!=null){
chain.doFilter(req,res);
//如果未登陆
}else{
hres.sendRedirect( "login.jsp ");
chain.doFilter(req,res);
}
}

//销毁过滤器
public   void   destroy()   {
this.filterConfig=null;
}
//初始化过滤器
public   void   init(FilterConfig   arg0)   throws   ServletException   {
this.filterConfig=arg0;
}
}

web.xml

  <filter>
        <filter-name> isLogin </filter-name>
        <filter-class> com.cdclive.hotel.common.filter.SignonFilter </filter-class>
  </filter>
  <filter-mapping>
        <filter-name> isLogin </filter-name>
        <url-pattern> /member/* </url-pattern>        
  </filter-mapping>


当我登陆member下的一个页面的时候:
java.lang.IllegalStateException
org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:352)
org.apache.jsp.member.accountsManage_jsp._jspService(accountsManage_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.cdclive.hotel.common.filter.EncodingFilter.doFilter(EncodingFilter.java:39)
com.cdclive.hotel.common.filter.SignonFilter.doFilter(SignonFilter.java:44)

这是为什么     小弟我对过滤器       没研究       大哥大姐们     耐心教一下

------解决方案--------------------
删掉第二个chain.doFilter(req,res);
  相关解决方案