• 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

Question about redirecting.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

According to HFSJ, I should get an IllegalStateException if I try to redirect or dispatch the request AFTER writing to the response. The problem is that isn't happening. Why not?

In any servlet's doPost():


The sendRedirect() is simply ignored. If I comment the flush() line, it gets redirected, but still without the exception.

Thank you.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The sendRedirect() is simply ignored. If I comment the flush() line, it gets redirected, but still without the exception.



After the flush(), the server surly throw the exception, bu as the response is commited it will not display in your browser. Check your server log. It should printed there.

Without flush, though you are writing to the response writer, the response is not commited ( as thers is some buffering for the writer), the serdRedirect will work without any exception.

Thanks
 
Otto Teixeira
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right.

SEVERE: Servlet.service() for servlet Testando threw exception
java.lang.IllegalStateException: Cannot forward after response has been committed



I was thinking about something like that... the exception being "hidden" by the container.

Thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic