Originally posted by deepa raj:
ServletOutputStream.flush() and ServletOutputStream.write() will commit the response.
is this true or not?
Only ServletOutputStream.flush() will commit the response and not ServletOutputStream.write(). ServletOutputStream.write() is a method which the ServletOutputStream inherits from OutputStream. It is used to write bytes to the target of the OutputStream. ServletOutputStream adds overloaded print and prinln methods to send String and other type of output to the target or destination. So you should use them and not write()
Originally posted by Paulo Rezende:
But if I use RequestDispatcher both flush() and write() will cause a IllegalStateException, right?
You mean that if you forward your request after a flush or write then it will throw an IllegalStateException. Ya it's true because when you write something to the output it will be automatically flushed(depending upon the implementation of ServletOutputStream in the Servlet library of the server as ServletOutputStream is abstract).
An IllegalStateException is thrown if any content has been sent to the output stream before request dispatching.