开发者

java filter forward throwing illegalstateexception

开发者 https://www.devze.com 2023-02-02 13:51 出处:网络
i m intercepting the request url and forwarding that to another url like some_application/image_20.jpeg to some_application/image_345.jpeg

i m intercepting the request url and forwarding that to another url

like

some_application/image_20.jpeg to some_application/image_345.jpeg

I am doing this using filters.

now my code is:

   public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain)
    throws IOException, ServletException {
    //some code

    RequestDispatcher request_Dispatcher=request.getRequestDispatcher(forward_url);
    request_Dispatcher.forward(request,response);



 Throwable problem = null;
 try {
 chain.doFilter(request, response);
 }

    catch(IllegalStateException ise)
    {

    }
    catch(Throwable t) {

 problem = t;
 t.printStackTrace();
}

  }
}

as i m using RequestDispatcher to forward requests.. and its working correctly

is it normal for this code to throw IllegalStateException

as i catch it in my code and lea开发者_StackOverflowve it not to throw any messages..

now i m worried if it can harm the overall container or slow the performance

or i can change some code and not get any IllegalStateException

thanks


request_Dispatcher.forward(request,response);
chain.doFilter(request, response);

You cannot do both these things. By the time you pass the request along the chain to the end resource, you have already committed a response via forward.

0

精彩评论

暂无评论...
验证码 换一张
取 消