Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call to sendRedirect() and getSession() after forward() throws IllegalStateException

 
chandrakant karale
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using a url rewrite filter from tuckey.org/urlrewrite; which using a configuration forwards request to a servlet depending on the pattern of requested URL. Lets say this servlet is AServlet.
Can this AServlet use sendRedirect() call ?

What I understand is that once a forward is executed, response is committed and sendRedirect will throw IllegalStateException?

Currently I am getting lot of IllegalStateException for getSession() calls and sendRedirect() calls in the AServlet.
I need to get rid of these exceptions.

Thanks

ck

 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should either forward or redirect, why trying both? I think you are aware of the difference between them?
 
chandrakant karale
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should either forward or redirect, why trying both?


The Urlrewrite library which is being used, does a forward internally. All requests are handled by urlrewrite filter at the first level. So I cannot avoid that.

My query is that just by calling forward on a request - the response gets committed ? even if nothing was written explicitly to the response.


To detail out how things are working at my end :

Lets say user accesses a short url http://test.myurl.com/section/News.

The request is handled by url-rewrite filter which forwards it to a resource(servlet) identified by mappings present with url-rewrite filter.
This resource , depending on some logic may call sendredirect.
Will there be an issue on this call?

Thanks

Chandrakant


 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chandrakant karale wrote:This resource , depending on some logic may call sendredirect. Will there be an issue on this call?

As long as you have not commited anything from that resource before the redirect, No problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic