正在处理的页面只是在错误/异常中途留空,而不是转发到 web.xml 中指定的错误页面
Posted
技术标签:
【中文标题】正在处理的页面只是在错误/异常中途留空,而不是转发到 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 【发布时间】:2014-12-31 17:30:42 【问题描述】:在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>
当发生任何异常(导致 500 内部服务器错误)时,请求将被分派到指定的错误页面,但是当发生异常时,正在处理的页面只是中途留空。它不会转发到错误页面。
如下配置java.lang.Throwable
或java.lang.Exception
,
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/error_pages/GeneralError.xhtml</location>
</error-page>
也没有帮助了。
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>
还尝试了一个只有一个 XHTML 页面且除了 web.xml 中的错误页面配置之外的空白项目。当发生异常时(在其他 HTTP 状态中,只有 404 有效),页面只是在中途留空,而不是转发到错误页面。
发生异常/错误时如何分派到指定的错误页面?
更新 1:
根据this 问题/答案,我将上下文参数javax.faces.FACELETS_BUFFER_SIZE
添加到web.xml 以获得64KB 的缓冲区大小,但没有发生任何新情况。如果发生异常,它仍然不会转发到错误页面。如果发生异常/错误,页面只是部分处理并在中途留空。异常堆栈跟踪仅在服务器终端上找到,而不在网页上找到(以防 500 内部服务器错误)。我特意让应用抛出异常来看看,是否转发到错误页面。
更新 2:
在编辑 1 中提到的设置缓冲区大小后,我在某个时间(成功登录后将请求重定向到安全区域)遇到以下异常。因此,我暂时删除了该参数。
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)
更新 3:
我尝试增加缓冲区大小(100002400
太大了),直到发出错误 java.lang.OutOfMemoryError: Java heap space
。因此,输出缓冲区大小应该不是问题。
在 Ajaxical 方面,顺便说一下,错误页面通过 OmniFaces - org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory
在faces-config.xml
中配置的异步请求期间的错误正确呈现。
也许,如果我在开始时配置了错误页面,就可以看到问题的原因 - 当我启动应用程序时,应用程序因此没有太多额外的开销,它目前有许多 XHTML 页面、CDI 管理的 bean、EJB 会话 bean 等,但无论如何我都不知所措。
更新 4:
我现在在 WildFly 9.0.2 final 上运行相同的应用程序。问题依旧。
【问题讨论】:
您是否在完全不同的容器中尝试过这个?也许是 JBoss? 它只是 GlassFish Server 4.1,它是唯一部署到服务器的应用程序。 GlassFish 运行时,其他服务器已关闭。 @kolossus 我的意思是,您应该尽量消除容器中出现错误的可能性;尝试将同一个应用部署到不同的容器中 Superficially WildFly does not properly interact/communicate with NetBeans IDE 我也不习惯使用 Eclipse 或其他 IDE,如 intelliJ。因此,我发现现在很难将应用程序部署到不同的服务器。 @kolossus 当您使用 OmniFaces 时,请考虑使用GzipResponseFilter
。与FullAjaxExceptionHandler
一样,它强制缓冲所有内容,直到javax.faces.FACELETS_BUFFER_SIZE
。这不是一个解决方案,但它应该可以解决这个问题。
【参考方案1】:
通过增加错误页面 GeneralError.xhtml 的大小来检查。 如果错误页面较小,有时服务器不会显示错误页面。 即尝试向 GeneralError.xhtml 添加更多 50-100 行文本并检查)
【讨论】:
这不是特定于服务器的。这是特定于浏览器的。特别是由雷德蒙德某处的团队开发的那个。无论如何,有更好的方法来显示错误页面。此外,这不是 OP 的具体问题的原因,因为有问题的浏览器不会显示一个完全空白的页面。 当服务器没有显示正确的页面时,浏览器会选择显示其默认的错误页面。 如前所述,这不是问题所在。再次阅读问题。如果你真的什么都不懂,你为什么要回答呢?以上是关于正在处理的页面只是在错误/异常中途留空,而不是转发到 web.xml 中指定的错误页面的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5刀片在出现错误而不是抛出异常时显示空白页面