File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how flush() method sends response? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how flush() method sends response?" Watch "how flush() method sends response?" New topic
Author

how flush() method sends response?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


This code will give IllegalStateException because response has already been sent to the client at line 2.

How flush() method sent the response to the client???

If I am not wrong, here flush() method cleans the output stream and write that data (that was written on output stream) into response....

Please comments.

Thanks.
[ December 01, 2005: Message edited by: rathi ji ]
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
flush doesn't cause the output to be written to response...instead the response that you will be sending to the client is buffered and that buffer is sent to the client.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


flush doesn't cause the output to be written to response...instead the response that you will be sending to the client is buffered and that buffer is sent to the client.


That may not be true.

Whatever you write to the output stream, the content is stored in a buffer and when you call flush(), the contents of the buffer are written to the browser. The buffer will also flush when it's reached its capacity.

That's why when you try to redirect after flushing (either explicitly or otherwise), you get an IllegalStateException because output has already been written to the browser.

cheers,
ram.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by ramprasad madathil:


That may not be true.

Whatever you write to the output stream, the content is stored in a buffer and when you call flush(), the contents of the buffer are written to the browser. The buffer will also flush when it's reached its capacity.

That's why when you try to redirect after flushing (either explicitly or otherwise), you get an IllegalStateException because output has already been written to the browser.

cheers,
ram.


Thanks Ram.



But is writing to browser???
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


But is writing to browser???


Sending the response over the network.

As I said earlier, when the output stream is written to, it doesnt immediately write the output to the browser (well, you can configure it that way too). Instead whatever is written is stored in a buffer and whenever the buffer is full or flush() is explicitly called, the contents of the buffer are is sent over to the browser.

ram.
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Originally posted by ramprasad madathil:


That may not be true.

Whatever you write to the output stream, the content is stored in a buffer and when you call flush(), the contents of the buffer are written to the browser. The buffer will also flush when it's reached its capacity.


I meant that too..though,in my case,the wordings should have been proper
[ December 01, 2005: Message edited by: Sunny Kumar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how flush() method sends response?