File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Illegatstateexception !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Illegatstateexception !!!" Watch "Illegatstateexception !!!" New topic

Illegatstateexception !!!

Nishant Dhar

Joined: Sep 09, 2005
Posts: 26

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 !!!

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You have forwarded the request/response objects, so you have transferred control, and you should get an exception.

So much trouble in the world -- Bob Marley
Troy Peter

Joined: Oct 13, 2005
Posts: 14
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.

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

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.


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
I agree. Here's the link:
subject: Illegatstateexception !!!
jQuery in Action, 3rd edition