我正在获取 exception-org.apache.catalina.core.ApplicationDispatcher.invoke threw exception java.lang.IllegalStateException

2022-09-04 23:34:59

我在服务器日志中收到以下错误,

08-May-2018 12:00:07.460 SEVERE [https-jsse-nio-8443-exec-1] org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet [jsp] threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:624)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at org.springframework.security.web.util.OnCommittedResponseWrapper.getWriter(OnCommittedResponseWrapper.java:149)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:111)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:176)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
    at org.apache.jsp.WEB_002dINF.views.uncaughtException_html._jspService(uncaughtException_html.java:209)


    08-May-2018 12:00:07.468 SEVERE [https-jsse-nio-8443-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [xyz] in context with path [] threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause java.lang.IllegalStateException: getOutputStream() has already been called for this response     
    at org.apache.catalina.connector.Response.getWriter(Response.java:624)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at org.springframework.security.web.util.OnCommittedResponseWrapper.getWriter(OnCommittedResponseWrapper.java:149)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:111)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:176)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
    at org.apache.jsp.WEB_002dINF.views.uncaughtException_html._jspService(uncaughtException_html.java:209)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

我不知道哪个方法抛出此错误以及此错误的原因是什么。实际上,这个异常发生在我在tomcat中部署我的应用程序并试图获取索引页面时(有时是第一次,有时是第二次,有时是第三次,无论何时到来,它都会来临),实际上根据我的配置,当我启用ssl时,当我部署我的应用程序并试图获得欢迎页面会话过期页面时,就会调用,从现在开始,一旦我试图获取其他一些页面,它就会被调用引发上述异常。我正在使用弹簧4,弹簧安全,maven,冬眠4。任何人都可以帮我吗?任何帮助都将得到通知。

网.xml

<web-app>
    <display-name>Smart app Application</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-security.xml, /WEB-INF/app-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

    <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>/WEB-INF/views/*</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>application</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index</welcome-file>
    </welcome-file-list>

    <session-config>
        <session-timeout>50</session-timeout>
    </session-config>
</web-app>

答案 1

如果您有一个 SimpleMappingExceptionResolver 尝试检查是否与 ControllerAdvice 注释的类有冲突。只能在一个位置处理异常。

正如我所说,它可能是由循环关系和Jackason作为序列化程序生成的。在这里,您有一些选项,例如使用DTO来简化答案或用户@JsonIgnore。


答案 2

推荐