File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how flush() method sends response?

 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic