• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic