Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegatstateexception !!!

 
Nishant Dhar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I understand that if I commit the response in some way by doing a write(), println() or a flush before I do the sendRedirect or RequestDispatcher forward, I will get an illegalstatexception.

But what happens if I try to write to the response in the forwarding servlet after the sendRedirect or RequestDispatcher method call.

Thanks !!!

Nishant
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have forwarded the request/response objects, so you have transferred control, and you should get an exception.
 
Troy Peter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nishant,

I haven't tried that before but my guess is if you try somehow to write to the response after the forward call then nothing is going to happen (code not executed) since control will have been already transferred to the forwarded page.

Troy.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Let me try to explain the above case.

1. The servlet call the requestDispatche forward method. let the response is not committed so no problem.

2. After successfully executing the forward method. it will return to next line os the forward message.

3. Here the execution of the code in original servet resumes, but the response is committed so there is no way to display anything on the browser.

4. As you try to write somthing on the out, it throw the exception but can not show to the client as the response is already committed. But I can see the exception in server log.


Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic