【问题标题】:Java 6 EE Navigate to Error Page When Getting JSonParseException获取 JSonParseException 时 Java 6 EE 导航到错误页面
【发布时间】:2014-11-27 09:19:48
【问题描述】:
我正在使用 PrimeFaces 5.0、Java 6 ee。
发生 com.fasterxml.jackson.core.JsonParseException 时如何导航到 error.jsf 页面?
哪个 java 类抛出 JsonParseException 并不重要。我必须在发生的任何地方处理异常。
【问题讨论】:
标签:
json
jakarta-ee
jsf-2
primefaces
exception-handling
【解决方案1】:
创建一个错误的 xhtml 页面。
在您的 web.xml 中,您可以配置对某些错误代码或异常类型起作用的错误页面元素。通常,您可以在 web.xml 的末尾配置以下内容:
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/jsfpages/errorpages/errorPage500.xhtml</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/WEB-INF/jsfpages/errorpages/errorPage503.xhtml</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/WEB-INF/jsfpages/errorpages/errorPage500.xhtml</location>
</error-page>
要处理与 ajax 相关的异常,您可以使用 omnifACES FullAjaxExceptionHandlerFactory。
http://balusc.blogspot.in/2012/03/full-ajax-exception-handler.html