wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes calling println method after commit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "calling println method after commit" Watch "calling println method after commit" New topic
Author

calling println method after commit

Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi All,

I have doubt regarding committing response. As per my knowledge response is committed either when the buffer is full or when we flush the buffer. But my doubt is regarding usage of println() method after the buffer is flushed.
Say I have a code snippet like:

PrintWriter out = response.getWriter();
out.println("This is a test");
out.flush();
out.println(response.isCommitted());
out.println("Test again");

When I try this I am not getting IllegalStateException, everything works fine. It also displays true for isCommitted() method. Should it be throwing this exception and in case not then does it imply that the output can be sent to client even after the response is committed.

-Rancy


Thanks,<br />-Rancy
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

When I try this I am not getting IllegalStateException

Why do you think you'll get one ? Nothing prevents you to continue writing to the output.


[My Blog]
All roads lead to JavaRanch
Rohit Sajan
Ranch Hand

Joined: Jun 15, 2006
Posts: 34
Hey your printing something, then flushing and then printing again. What's wrong in that. It's perfectly fine. If you are forwarding something after flushing you will get IllegalStateException

Saju
madhav changala
Ranch Hand

Joined: Dec 20, 2005
Posts: 57
hi

You will get the exception only when you forward the request after flushing the output..

It is also container dependent

Regards


saivenumadhav
Rancy Chadha
Ranch Hand

Joined: Jul 12, 2006
Posts: 135
Hi All,

Thanks to all of you for your replies.
The reason I asked this question was: I was under the impression that once the response stream is committed any other attempt to write to it would result in an IllegalStateException, except if it is after a sendError or sendRedirect, in which case it will simply be ignored. Also any attempt to add a header or content type to the response after it is committed will also be ignored. Other than that any attempt to write to the response stream will result in an IllegalStateException. Probably I am not clear with the concept of committing the response. So far from what I have understood I think committing response means ensuring that data in the buffer has been sent to the client. If some one can explain the concept of committing the response to me I would really appreciate that.

Thanks,
-Rancy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling println method after commit
 
Similar Threads
doubt in flushBuffer
doubt in Exception occured by sendError()
A doubt on forward(req,resp)
RequestDispatcher.forward()
Doubt on RequestDispatcher