Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling close() on ServletOutputStream

 
tom walters
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a ServletOutputStream in my doPost method obtained via response.getOutputStream(). Should we call close() on it at the end of the doPost/doGet method? I remember reading somewhere that we should not call close() on a ServletOutputStream and instead only call flush().
 
Tim Holloway
Saloon Keeper
Posts: 18302
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My experience is that sometimes the container can behave in strange ways, and I have, in deperation, explicitly closed or flushed the output stream, but technically, you shouldn't close it, and I get the impression that flush() may be being overused as well.
However, calling close() on an already closed stream is supposed to have no effect, so the fact that BOTH you and the container close the stream is - in theory - OK.
In practice, you are living dangerously, since the container might conceivably find a reason to put something in the stream AFTER you exit the servlet method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic