简体   繁体   English

正在处理的页面仅在错误/异常中途留空,而不是转发到web.xml中指定的错误页面

[英]Pages being processed are merely left blank half way through on errors/exceptions instead of forwarding to the error page specified in web.xml

In web.xml, I have the following configurations for a global error page. 在web.xml中,我有一个全局错误页面的以下配置。

<error-page>
    <error-code>401</error-code>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

<error-page>
    <error-code>403</error-code>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

<error-page>
    <error-code>503</error-code>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

When any exception occurs (that result in 500 internal server error), the request is expected to be dispatched to the error page specified but when an exception occurs, the page which is being processed is just left blank in half way through. 当发生任何异常(导致500内部服务器错误)时,请求将被分派到指定的错误页面,但是当发生异常时,正在处理的页面在中途保持空白。 It does not forward to the error page. 它不会转发到错误页面。

Configuring java.lang.Throwable or java.lang.Exception as follows, 配置java.lang.Throwablejava.lang.Exception ,如下所示,

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>

also did not help anymore. 也没有帮助了。


The full contents of web.xml : web.xml的全部内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/my.taglib.xml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>

    <context-param>
        <param-name>com.sun.faces.enableViewStateIdRendering</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>

    <context-param>
        <param-name>log4jExposeWebAppRoot</param-name>
        <param-value>false</param-value>
    </context-param>

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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


    <error-page>
        <error-code>401</error-code>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <error-page>
        <error-code>403</error-code>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <error-page>
        <error-code>503</error-code>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/WEB-INF/error_pages/GeneralError.xhtml</location>
    </error-page>

    <security-constraint>
        <display-name>AdminConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>ROLE_ADMIN</web-resource-name>
            <description/>
            <url-pattern>/admin_side/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>ROLE_ADMIN</role-name>
        </auth-constraint>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <security-constraint>
        <display-name>UserConstraint</display-name>
        <web-resource-collection>
            <web-resource-name>ROLE_USER</web-resource-name>
            <description/>
            <url-pattern>/user_side/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>ROLE_USER</role-name>
        </auth-constraint>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>


    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>projectRealm</realm-name>
        <form-login-config>
            <form-login-page>/utility/Login.xhtml</form-login-page>
            <form-error-page>/utility/ErrorPage.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <description/>
        <role-name>ROLE_ADMIN</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>ROLE_USER</role-name>
    </security-role>
    <!--error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/utility/Login.xhtml</location>
    </error-page-->

    <session-config>
        <session-timeout>
            120
        </session-timeout>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>
    <welcome-file-list>
        <welcome-file>utility/Login.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

Also tried on a blank project with only a single XHTML page and nothing other than error page configurations in web.xml. 还尝试了一个只有一个XHTML页面的空白项目,除了web.xml中的错误页面配置。 Pages are merely left blank half way through instead of forwarding to the error page, when an exception occurs (among other HTTP status, only 404 works). 当发生异常时(在其他HTTP状态中,仅404工作),页面仅在中途空白而不是转发到错误页面。

How to dispatch to a specified error page, when any exception/error occurs? 当发生任何异常/错误时,如何分派到指定的错误页面?


Update 1 : 更新1:

According to this question/answer, I added the context parameter javax.faces.FACELETS_BUFFER_SIZE to web.xml to have 64KB buffer size but nothing new happened. 根据这个问题/答案,我将上下文参数javax.faces.FACELETS_BUFFER_SIZE添加到web.xml以具有64KB的缓冲区大小,但没有发生新的事情。 It still does not forward to the error page, if an exception occurs. 如果发生异常,它仍然不会转发到错误页面。 Pages are just partially processed and left blank in half way through, if an exception/error occurs. 如果发生异常/错误,页面将被部分处理并在中途保持空白。 The exception stacktrace is only found on the server terminal and not on the web page (in case 500 internal server error). 异常堆栈跟踪仅在服务器终端上找到,而不在网页上(如果500内部服务器错误)。 I deliberately make the application throw an exception to see, if it forwards to the error page. 我故意让应用程序抛出异常,看它是否转发到错误页面。


Update 2 : 更新2:

After setting the buffer size as mentioned in edit 1, I got the following exception at a certain time (when a request is redirected to a secured area after a successful login). 在编辑1中提到的设置缓冲区大小之后,我在某个时间(在成功登录后将请求重定向到安全区域时)得到以下异常。 So, I removed that parameter for now. 所以,我现在删除了该参数。

Severe:   Error Rendering View[/utility/Login.xhtml]
java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:285)
    at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:923)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1162)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:403)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at filter.LoginNocacheFilter.doFilter(LoginNocacheFilter.java:39)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Info:   Exception when handling error trying to reset the response.
java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:285)
    at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:923)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1162)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:403)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at filter.LoginNocacheFilter.doFilter(LoginNocacheFilter.java:39)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Update 3 : 更新3:

I tried to increase the buffer size ( 100002400 that's too much) until the error java.lang.OutOfMemoryError: Java heap space is issued. 我试图增加缓冲区大小( 100002400太多),直到发出错误java.lang.OutOfMemoryError: Java heap space Therefore, the output buffer size should not be the problem. 因此,输出缓冲区大小应该不是问题。

In Ajaxical things, error pages by the way, are correctly rendered on errors during asynchronous requests by means of OmniFaces - org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory configured in faces-config.xml . 顺便提一下,在Ajaxical中,错误页面通过在faces-config.xml配置的OmniFaces - org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory在异步请求期间正确呈现错误。

Perhaps, it could have been possible to see the cause of the problem, if I had configured error pages in the beginning - when I started the application and the application consequently had no much extra overhead that it currently has with many XHTML pages, CDI managed beans, EJB session beans etc but anyway I overwhelmed it. 也许,有可能看到问题的原因,如果我在开始时配置了错误页面 - 当我启动应用程序时,应用程序因此没有太多的额外开销,它目前与许多XHTML页面,CDI管理bean,EJB会话bean等,但无论如何我压倒了它。


Update 4: 更新4:

I am now running the same application on WildFly 9.0.2 final. 我现在在WildFly 9.0.2 final上运行相同的应用程序。 The problem remains unchanged. 问题依然没有改变。

Check by increasing the size of your error page GeneralError.xhtml. 通过增加错误页面GeneralError.xhtml的大小来检查。 Sometimes the server doesn't display the error page if it is smaller in size. 有时,如果服务器的大小较小,则不会显示错误页面。 ie try adding some more 50-100 lines of text to GeneralError.xhtml and check) 即尝试向GeneralError.xhtml添加更多50-100行文本并检查)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM