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语句。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx sub_filter指令用于在代理服务器上替换响应内容中的某个字符串。在给定的配置样例中,sub_filter指令被用来重定向URL。在第一个配置样例中,sub_filter指令将响应中的'http://www.nginxbar.com/'替换为'http://www.nginxbar.org/books'。这样,当客户端访问'/books',代理服务器会将请求转发到'http://www.nginxbar.com',并将响应中的重定向URL替换为'http://www.nginxbar.org/books'。在第二个配置样例中,sub_filter指令用于替换'/login'为'/j/login','/static/'为'/j/static/',以及'/adjuncts'为'/j/adjuncts'。这样,当客户端访问'/j/',代理服务器会将请求转发到'http://127.0.0.1:8002',并将响应中对应的字符串进行替换。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [当Nginx遇到重定向](https://blog.csdn.net/hzbooks/article/details/109324553)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [nginx add_header指令使用方法](https://download.csdn.net/download/weixin_38735541/12903169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [nginx中的sub_filter](https://blog.csdn.net/scugxl/article/details/105460177)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值