問題点
jsp ファイルを実行しようとすると、次のようなエラーログがインスタンスに表示されます。
14:55:42 *ERROR* delivery: Unhandled Exception: java.lang.IllegalStateException: OutputStream already obtained java.lang.IllegalStateException: OutputStream already obtained
解決策
Line killer を使用し、ファイル内にスペースやキャリッジリターンがないことを確認します。上記の jsp の適切な実装は次のとおりです。
<%@ 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(); %>
jsp ではなく、サーブレットを使用して画像を処理できます。
追加情報
この問題は、JSP 内でユーザーが応答の出力ストリームを取得しようとしたが、既に取得されている場合に発生します。jsp コードに空の行がある可能性があります。このエラーを生成するイメージのスプール例を次に示します。
<%@ 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(); %>
アカウントにログイン