我正在使用 PrimeFaces 5.1 开发 JSF 2.2,在我的异常处理应用程序中,我在 web.xml 中配置了错误代码 500,如下所示
<error-page>
<error-code>500</error-code>
<location>/500.xhtml</location>
</error-page>
在 500.xhtml 中,我尝试访问如下错误代码
<h:outputText value="#{requestScope['javax.servlet.error.status_code']}"></h:outputText>
在测试时我发现,我被重定向到如下所示的网址
https://localhost:8443/appname/500.xhtml
这是错误的,它应该像 https://localhost:8443/appname/configerd_path
在这里我发现在 requestScope
中我没有 javax.servlet.error.*
所以我无法显示错误代码、错误消息等...
我想问一下,在 JSF 2.2 中处理此类错误的最佳实践是什么?如何访问错误代码和错误消息?
最佳答案
当我使用 primefaces 时,它提供了内置 exception handler轻松处理ajax和非ajax请求中的异常。
使用以下 EL,我能够在 500.xhtml 页面捕获异常。
<h:outputText value="#{pfExceptionHandler.exception}" ></h:outputText>
<h:outputText value="#{pfExceptionHandler.type}"></h:outputText>
<h:outputText value="#{pfExceptionHandler.message}" ></h:outputText>
我希望它能帮助其他人:-)
关于jsf - 使用 PrimeFaces 5.1 无法访问 JSF 2.2 中错误代码 500 的 javax.servlet.error.*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28234147/