混合 JSF Facelet 和 JSP 渲染器时出现偶发性 java.lang.IllegalStateException 异常

发布于 2024-10-04 14:05:52 字数 5517 浏览 3 评论 0原文

我正在开发一个相当旧的 Web 应用程序,它包含以下技术。

  • SUN JSF RI
  • 1.1facelets-api 1.1.14
  • JBOSS 4.0.2
  • Quipukit 1.6(AJAX JSF 组件库)

该应用程序最初是使用 JSP 渲染器开发的。对于即将添加的新功能,我们希望切换到 Facelet,但我们无法重写其余部分,因此我们必须并行运行 Facelet 和 JSP 渲染。一般来说,这是可行的,但在某些情况下(不可重现),我们在应用程序的 JSP 部分遇到以下异常。

    15:34:45,995 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: getWriter() has already been called for this response
    at org.apache.catalina.connector.Response.getOutputStream(Response.java:565)
    at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:171)
    at teamdev.jsf.util.ResourceFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:619)

当异常发生时,它会导致一些奇怪的行为,例如在下一个操作中未正确提交值(显然 JSF 阶段尚未正确处理)

以下是我的 web.xml 和 faces.config 中的相关部分

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


        <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/faces-config.xml</param-value>
        </context-param>


        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.jsp</param-value>
        </context-param>

        <!-- Use Documents Saved as *.xhtml -->
        <context-param>
            <param-name>facelets.VIEW_MAPPINGS</param-name>
            <param-value>*.xhtml</param-value>
        </context-param>

        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/faces-config.xml</param-value>
            </init-param>
            <init-param>
                <param-name>debug</param-name>
                <param-value>3</param-value>
            </init-param>
            <init-param>
                <param-name>detail</param-name>
                <param-value>3</param-value>
            </init-param>
            <load-on-startup>0</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>

        <session-config>
            <session-timeout>60</session-timeout>
        </session-config>

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







<faces-config>
    <application>
        <message-bundle>validatormessages</message-bundle>
        <locale-config>
            <default-locale>de_DE</default-locale>
            <supported-locale>en_GB</supported-locale>
            <supported-locale>en_US</supported-locale>
            <supported-locale>fr_FR</supported-locale>
        </locale-config>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>

...

</faces-config>

任何帮助都值得赞赏。

问候

I'am working on a rather old web application that incorporates the following technologies.

  • SUN JSF RI 1.1
  • facelets-api 1.1.14
  • JBOSS 4.0.2
  • Quipukit 1.6 (An AJAX JSF
    component library)

The application was originally developed with JSP renderer. For a new feature that will be added soon, we would like to switch to facelets, but we cant't rewrite the rest, so we'll have to run facelets and JSP rendering in parallel. Generally this works, but on some occasion (not reproducable) we get the following exception on the JSP parts of the application.

    15:34:45,995 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: getWriter() has already been called for this response
    at org.apache.catalina.connector.Response.getOutputStream(Response.java:565)
    at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:171)
    at teamdev.jsf.util.ResourceFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:619)

When the Exception occurs it causes some weird behaviour, like values aren't correctly submitted on the next action (obviously JSF phase have not been processed properly)

Here are the relevant parts from my web.xml and faces.config

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


        <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/faces-config.xml</param-value>
        </context-param>


        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.jsp</param-value>
        </context-param>

        <!-- Use Documents Saved as *.xhtml -->
        <context-param>
            <param-name>facelets.VIEW_MAPPINGS</param-name>
            <param-value>*.xhtml</param-value>
        </context-param>

        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/faces-config.xml</param-value>
            </init-param>
            <init-param>
                <param-name>debug</param-name>
                <param-value>3</param-value>
            </init-param>
            <init-param>
                <param-name>detail</param-name>
                <param-value>3</param-value>
            </init-param>
            <load-on-startup>0</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>

        <session-config>
            <session-timeout>60</session-timeout>
        </session-config>

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







<faces-config>
    <application>
        <message-bundle>validatormessages</message-bundle>
        <locale-config>
            <default-locale>de_DE</default-locale>
            <supported-locale>en_GB</supported-locale>
            <supported-locale>en_US</supported-locale>
            <supported-locale>fr_FR</supported-locale>
        </locale-config>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>

...

</faces-config>

Any help ist appreciated.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被你宠の有点坏 2024-10-11 14:05:52

当 JSP 使用 scriptlet 表达式 (<%= %>) 或显式写入输出时,JSP 将调用 getWriter()通过 scriptlet 中的 out.print (<% %>)。

验证您的 JSP 页面中是否没有任何此类内容。

JSP will call getWriter() when it's using scriptlet expressions (<%= %>) or when you're explicitly writing to output by out.print in a scriptlet (<% %>).

Verify if you don't have any of such things in your JSP pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文