aspose file tools*
The moose likes Servlets and the fly likes filters - getting IllegalStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "filters - getting IllegalStateException" Watch "filters - getting IllegalStateException" New topic
Author

filters - getting IllegalStateException

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi,

I have a web.xml file which has filter mapping something like this:



The code of filter class is something like this:



All filter classes has same kind of code - they redirect to a URL.

I am getting an exception here:



This exception comes when we forward or include request after response is written.

I am not able to figure out what's happening here. Please help.

Thanks.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Simply don't run FilterChain#doFilter() or RequestDispatcher#forward() or RequestDispatcher#include() after the HttpServletResponse#sendRedirect() call.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Bauke Scholtz wrote:Simply don't run FilterChain#doFilter() or RequestDispatcher#forward() or RequestDispatcher#include() after the HttpServletResponse#sendRedirect() call.



Thanks. But...

Consider a URL:

http://localhost:8001/mail/a/one

This would be redirected to:

http://localhost:8001/mail/a/two

It's the same pattern so filter called again and again and again...

It's not calling the next filter.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just check the URL before replacing. If it is subject to replace, then replace and redirect, else continue with request.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: filters - getting IllegalStateException