• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

filters - getting IllegalStateException

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic