• 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

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.
 
I AM MIGHTY! Especially when I hold 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