Hi all, Could anybody tell me,how response is commited in servlet?Also I wan to know how calling sendRedirect() on servletResponse throws illegalStateexception after response is commited? It will be greate , if you can explain it with a code snippet.Any typing mistakes , please ignore.
Thanks in advance
Cheers<br />-------------<br />Swapnil<br /> <br />SCJP5-81%<br /> <br />"Dictionary is the only place where Success come before Work"
The text of a response - response headers plus whatever has been written by the servlet to an output stream - is held until either: 1. the flush() method of the output stream is called -or- 2. the output buffer gets filled and flushed
At that point, since the response headers have been sent, it is impossible to modify them so trying to do so causes the exception.
There is no need for a code snippet, this is all covered in the servlet Javadocs an API documentation.
Thanks William. I have one more doubt.I understood that calling sendRedirect() after committing response causes IllegalStateException. I tried this example from SCWCD book of Hanumant Deshmukh.But it does not throw any exception.Check it out..
Firstly: as Rahul says, what do you get on the client side?
If it does not fail, then you have to assume that there are ways in which flush() can be called that does not cause the stream to be committed. The most likely way that I can think of is that flush() is a request to the stream to flush but does not actually cause the data to be sent itself, like calling repaint() in AWT.
If you make 400 repaint() calls, it will not necessarily result in paint() being called 400 times. When Java gets a chance it will call paint(). If 50 repaint() requests are waiting you'll only get one paint().
Back to streams, if the stream is managed in a separate thread then this must certainly be the case, otherwise you run the risk of threads blocking on a failed or delayed write.
I'd try flush() then wait for a second or so after it and see if that changes things.