Error: OutputStream already obtained

Issue

When you try to run your jsp file, you get an error in your instance error.log similar to the following:

14:55:42 *ERROR* delivery: Unhandled Exception: java.lang.IllegalStateException: OutputStream already obtained java.lang.IllegalStateException: OutputStream already obtained

Solution

Use line killers and make sure that there no spaces or carriage returns in the file. The proper implementation of the jsp shown above is as follows:

<%@ page import="java.io.*" %><% %><%@ page import="com.day.cq.delivery.DeliveryHttpServletRequest" %><% %><%@ page import="com.day.cq.activation.MimeTab" %><% %><%@ page import="com.day.cq.contentbus.*" %><% %><%@ page import="com.day.util.IO" %><% // Instanciate a Communiqué Request Object based on the implicite JSP-request DeliveryHttpServletRequest cqRequest = (DeliveryHttpServletRequest) request; // set the response ContentType information based on the request uri extension String mimeType = MimeTab.getContentType(cqRequest.getRequestURI()); response.setContentType(mimeType); // Using the request.getAtom() method if the Selectors define the Content Atom Atom atom = (Atom) cqRequest.getAtom(); // Instanciate and cast the Content Atom to a Java stream InputStream inputStream = atom.getStream(); IO.spool(inputStream, response.getOutputStream()); // close the input stream inputStream.close(); %>

Бележка:

You can use servlets to process images instead of jsp.

Additional information

This issue occurs if in your jsp you try to get the output stream of response, but it has already been obtained. There could be an empty line in the jsp code. Here is an image spooling example that generates this error:

<%@ page import="java.io.*" %> <%@ page import="com.day.cq.delivery.DeliveryHttpServletRequest" %> <%@ page import="com.day.cq.activation.MimeTab" %> <%@ page import="com.day.cq.contentbus.*" %> <%@ page import="com.day.util.IO" %> <% // Instanciate a Communiqué Request Object based on the implicite JSP-request DeliveryHttpServletRequest cqRequest = (DeliveryHttpServletRequest) request; // set the response ContentType information based on the request uri extension String mimeType = MimeTab.getContentType(cqRequest.getRequestURI()); response.setContentType(mimeType); // Using the request.getAtom() method if the Selectors define the Content Atom Atom atom = (Atom) cqRequest.getAtom(); // Instanciate and cast the Content Atom to a Java stream InputStream inputStream = atom.getStream(); IO.spool(inputStream, response.getOutputStream()); // close the input stream inputStream.close(); %>

 Adobe

Получете помощ по-бързо и по-лесно

Нов потребител?

Adobe MAX 2024

Adobe MAX
Конференцията, посветена на креативността

14 – 16 октомври, Маями Бийч и онлайн

Adobe MAX

Конференцията, посветена на креативността

14 – 16 октомври, Маями Бийч и онлайн

Adobe MAX 2024

Adobe MAX
Конференцията, посветена на креативността

14 – 16 октомври, Маями Бийч и онлайн

Adobe MAX

Конференцията, посветена на креативността

14 – 16 октомври, Маями Бийч и онлайн