getOutputStream() has already been called for this Response

Asked

Viewed 3,184 times

2

I created two identical error pages for two systems running within the same Tomcat. One of the pages works normally and the other occurs the following error. Within the development and homologation environment the error does not happen. Tomcat version of all environments is the same: 7.0.52

Grave: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/template/dispatch-error.jsp] org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:460)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:411)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:200)
at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:636)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:104)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:186)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:126)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)
at org.apache.jsp.template.dispatch_002derror_jsp._jspService(dispatch_002derror_jsp.java:236)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

Page JSP :

<%@page contentType="text/html; charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%@ page isErrorPage="true" import="java.io.*"%><div class="container">
    <c:choose>
        <c:when test="${pageContext.errorData.statusCode == '404' || pageContext.errorData.statusCode == '400' ||
                                    pageContext.errorData.statusCode == '0' }">
            <span class="laranja">
                <h1>A Página ou arquivo solicitado não foi encontrado, clique no botão Voltar do seu navegador<br/>
            </span>
        </c:when>
        <c:otherwise>
            <span class="laranja">
                <h1>Ocorreu um erro. Clique no botão voltar do seu navegador</h1>
                <br/>
            </span>
                <c:if test="${pageContext.errorData.statusCode == '500'}">
                    <div id="central">
                        <span id="mensagem" style="display: none;"></span>
                        <span id="error" style="display:none;">
                                <%=exception.getMessage()%>
                                <%
                                    StringWriter stringWriter = new StringWriter();
                                    PrintWriter printWriter = new PrintWriter(stringWriter);
                                    exception.printStackTrace(printWriter);
                                    out.println(stringWriter);
                                    printWriter.close();
                                    stringWriter.close();
                                %>
                        </span>
                    </div>
                </c:if>
        </c:otherwise>
    </c:choose>
</div>

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.