Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

closing ServletOutputStream

843841Jul 7 2006 — edited Jul 21 2006
What is the best practice handling the ServletOutputStream after the response has been written and the stream is flushed with flush() and you are about to return from the doGet or service method of the Servlet?

Should we close the ServletOutputStream or not? Closing ought to assure that any future write to this stream will throw. But this does not imply that the container will close the HTTP connection to the browser or discard any other underlying IO streams. The behavior is container dependent but there should be some guidance.

In my view, after return from Servlet.doGet or equivalent the ServletOutputStream instance should be guaranteed not to be used again. Calling close() should have no effect. How is it in practice?

-Thomas
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2006
Added on Jul 7 2006
5 comments
545 views