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.
You will get the exception only when you forward the request after flushing the output..
It is also container dependent
posted 13 years ago
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.