• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filters - getting IllegalStateException

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply don't run FilterChain#doFilter() or RequestDispatcher#forward() or RequestDispatcher#include() after the HttpServletResponse#sendRedirect() call.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just check the URL before replacing. If it is subject to replace, then replace and redirect, else continue with request.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic