If I call ServletResponse.flushBuffer()
,
do I need to call ServletResponse.getOutputStream().close()
and/or ServletResponse.getOutputStream().flush()
(same for ServletResponse.getWriter().close()
and/or ServletResponse.getWriter().flush()
) ?
Both flush()
and close()
are completely different methods:
flush() ...
Theflush()
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() ...
Theclose()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With