Runtime servletresponsewrapperinclude getoutputstream

Keywords: runtime servletresponsewrapperinclude getoutputstream
Description: I m trying to include (<jsp:include> output of servlet in my JSP page. I get following exception:- at

I m trying to include (<jsp:include> output of servlet in my JSP page. I get following exception:-

at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(

An IllegalStateException is generally thrown when an attempt is made to use the response object after the response has already been committed to the client.

That is, it is likely that the response in your servlet was committed at some point prior to: "ServletOutputStream sos = response.getOutputStream".

You can always check whether the response has been committed or not by using ServletResponse.isCommitted(), where a return value of 'false' indicates that the response has not yet been committed.

I have a jsp page the contents of which are static (character data). Now at the end of the page i need to call servlet to include dynamic contents (binary data). And in the servlet i set the buffer size and after that trying to get Output Stream where actually the code fails and i get an exception as described above. (NOTE :- The servlet has been tested and it works fine. No problem with servlet).

I tried to decompile ServletResponseWrapperInclude.class from jasper_runtime.jar file to trace the error. The method in that class file is throwing IllegalStateException when i call getServletOutputStream in my servlet. I am confused where actually the error is.

If i call jsp:forward i get the dynamic contents to be displayed but static data in buffer erases out which is the right behaviour.

Your JSP page, in it's servlet capacity, has called getWriter() on the response object to write out the static contents of the JSP page.

Ok so far. But now your included servlet attempts to get a ServletOutputStream on the same response object. This will cause an IllegalStateException. You may have one or the other, PrintWriter or ServletOutputStream. Not both.

Photogallery Runtime servletresponsewrapperinclude getoutputstream: