wood burning stoves 2.0*
The moose likes Servlets and the fly likes Regarding RequestDispatcher.forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding RequestDispatcher.forward" Watch "Regarding RequestDispatcher.forward" New topic
Author

Regarding RequestDispatcher.forward

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
I have one doubt:

I know that i can't write response to client before i call forward method of RequestDispatcher, But can i after call that?

My learning says that "I neither write respose before call of forward, nor after call of forward"

Is my understaning right?

Please help in clearing my concepts.

Thanks in Advance.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Before the request is dispatched to the client, accidentally output buffer
may written and closed so that output could go to the client.

And when the request is already dispatched, its not meaningful to write
anything to the buffer.

I remind, the output buffer is cleared before the request is dispatched to
the JSP from Servlet.


cmbhatt
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Chandra thanks for reply!!!

From your answer
----------------------------------------------
Before the request is dispatched to the client, accidentally output buffer
may written and closed so that output could go to the client.
---------------------------------------------

I think you are talking about following two lines:

os.flush(); that will send reponse to client before you call forward.

But if call forward after above statement you'll get IllegalStsteException
right?

Yes, i agree that there is no meaning to write response after calling forward.... but does it give me any exception???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, i agree that there is no meaning to write response after calling forward.... but does it give me any exception???


Did you try it?
If so, what happened?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding RequestDispatcher.forward
 
Similar Threads
Forward Referencing
How does server side forwarding exactly work?
RequestDipatcher
Forward from java class
Illegatstateexception !!!