Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Normally you should not close the stream. The servlet container will automatically close the stream after the servlet is finished running as part of the servlet request life-cycle. </p> <p>For instance, if you closed the stream it would not be available if you implemented a <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/Filter.html" rel="noreferrer">Filter</a>.</p> <p>Having said all that, if you do close it nothing bad will happen as long as you don't try to use it again.</p> <p>EDIT: <a href="http://java.sun.com/products/servlet/Filters.html" rel="noreferrer">another filter link</a></p> <p>EDIT2: adrian.tarau is correct in that if you want to alter the response after the servlet has done its thing you should create a wrapper extending HttpServletResponseWrapper and buffer the output. This is to keep the output from going directly to the client but also allows you to protect if the servlet closes the stream, as per this excerpt (emphasis mine): </p> <blockquote> <p>A filter that modifies a response must <em>usually</em> capture the response before it is returned to the client. The way to do this is to pass the servlet that generates the response a stand-in stream. The stand-in stream prevents the servlet from closing the original response stream when it completes and allows the filter to modify the servlet's response.</p> </blockquote> <p><a href="http://java.sun.com/products/servlet/Filters.html#72674" rel="noreferrer">Article</a></p> <p>One can infer from that official Sun article that closing the outputstream from a servlet is something that is a normal occurrence, but is not mandatory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload