java filter forward throwing illegalstateexception
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
.
精彩评论