A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Spring in Action
this week in the
Web Component Certification (SCWCD/OCPJWCD)
Joined: Sep 09, 2005
Oct 19, 2005 04:46:00
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
forward, I will get an illegalstatexception.
But what happens if I try to write to the response in the forwarding
after the sendRedirect or
Joined: Nov 06, 2000
Oct 19, 2005 09:39:00
You have forwarded the request/response objects, so you have transferred control, and you should get an exception.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Oct 13, 2005
Oct 19, 2005 10:43:00
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.
Joined: Dec 04, 2004
Oct 20, 2005 05:02:00
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.
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
It is sorta covered in the
JavaRanch Style Guide
subject: Illegatstateexception !!!
SendRedirect Vs RequestDispatcher
Why is this code not working ?
What is the difference between requestdispatcher and sendredirect?
forward() method of RequestDispatcher vs sendRedirect() on Response object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014