Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll attempt to address the more specific question raised in your example:</p> <blockquote> <p>consider a 3rd party filter that decorates the output of a request and it gets an OutputStream. How is a filter or a servlet that needs to work with a Writer supposed to "know" that an OutputStream was already opened and should it care? </p> </blockquote> <p>The Servlet API also disallows the use of both Writer and OutputStream when populating the response, as indicated in the API documentation for the <a href="http://download.oracle.com/javaee/6/api/javax/servlet/ServletResponse.html#getWriter%28%29" rel="nofollow">ServletResponse.getWriter() method</a>:</p> <blockquote> <p>Either this method or getOutputStream() may be called to write the body, not both.</p> </blockquote> <p>If a filter (third party or otherwise) wants to write to the response, especially after servlet(s) have generated it, it ought to assume that</p> <ul> <li>the servlet has used either the Writer or the OutputStream to populate the response. </li> <li>the servlet would have invoked the <code>close()</code> method on the Writer or the OutputStream object.</li> </ul> <p>To account for this, the filter must create a <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponseWrapper.html" rel="nofollow">HttpServletResponseWrapper</a> instance, pass it downstream to the servlet for population, read it back in again, and then populate the actual container-managed HttpServletResponse object.</p> <p>The above would also hold good if the filter were to populate the response first (before the request is processed further). It should perform the population on the actual HttpServletResponse object, pass a wrapper downstream, and then write the contents of the wrapper to the actual object.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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