filter重定向时报错

public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
 throws IOException, ServletException {
 
 if (debug) log("AuthenticationFilter:doFilter()");

 RequestWrapper  wrappedRequest  = new RequestWrapper((HttpServletRequest)request);
 ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse)response);
    
 doBeforeProcessing(wrappedRequest, wrappedResponse);
  
    System.out.println("in filter!!!!!!!!!!!!!!!!!!");
 if(wrappedRequest.getSession().getAttribute("user")==null)
    {
        System.out.println("you do not have permission jump!!!!!!!!!!!!!!!!!!!!!!!");
        wrappedResponse.sendRedirect(wrappedRequest.getContextPath()+"/home/login.jsp");
       
       
    }
     Throwable problem = null;
 try {
     chain.doFilter(request, response);
 }
 catch(Throwable t) {
     // If an exception is thrown somewhere down the filter chain,
     // we still want to execute our after processing, and then
     // rethrow the problem after that.
     problem = t;
     t.printStackTrace();
 }


 

 

 doAfterProcessing(wrappedRequest, wrappedResponse);

 // If there was a problem, we want to rethrow it if it is
 // a known type, otherwise log it.
 if (problem != null) {
     if (problem instanceof ServletException) throw (ServletException)problem;
     if (problem instanceof IOException) throw (IOException)problem;
     sendProcessingError(problem, response);
 }
    }

加粗字体为检查登陆逻辑,如果符合条件,触发重定向,则会报错:

java.lang.IllegalStateException: PWC1227: Cannot forward after response has been committed
修改方法:在if块最后加入return语句。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值