What does ServletResponse#flushBuffer() cover?

sp00m picture sp00m · Mar 4, 2013 · Viewed 7.7k times · Source

Answer

Ramesh PVK picture Ramesh PVK · Mar 4, 2013

Both flush() and close() are completely different methods:

flush() ...

The flush() method is used to flush the buffered response to the client. It will also lead to commit the response headers.

By default Server container will automatically call this if the internal buffer is reached.

You should call explicitly if you want to send the response in custom chunks.

close() ...

The close() method is used to close the response stream such that no more data can be written.

By default Server container will automatically call this at the end of Servlet life cycle.

You should call explicitly if you do not want to allow writing response beyond any point. Attempting to do so will throw an IOException.