Jsf Facelets自定义错误页-自定义/包装异常消息/堆栈跟踪
我正在使用JBossAS7。 我已经知道如何使用我自己的Jsf Facelets自定义错误页-自定义/包装异常消息/堆栈跟踪,jsf,exception,facelets,stack-trace,custom-error-pages,Jsf,Exception,Facelets,Stack Trace,Custom Error Pages,我正在使用JBossAS7。 我已经知道如何使用我自己的web.xml错误页面来处理HTTP错误(例如404500…),这不是问题。 但出于调试原因,我需要查看错误堆栈跟踪。如何访问默认显示的消息并将其嵌入错误页面?具体的异常实例作为请求属性提供,其名称为keyed,其值为 因此,这将给您一个例外: #{requestScope['javax.servlet.error.exception']} 但是,没有标准的工具可以在视图中打印堆栈跟踪。您需要这样做,就像在{of:printStackTr
web.xml
错误页面来处理HTTP错误(例如404500…),这不是问题。
但出于调试原因,我需要查看错误堆栈跟踪。如何访问默认显示的消息并将其嵌入错误页面?具体的异常实例作为请求属性提供,其名称为keyed,其值为 因此,这将给您一个例外:
#{requestScope['javax.servlet.error.exception']}
但是,没有标准的工具可以在视图中打印堆栈跟踪。您需要这样做,就像在{of:printStackTrace()}
的风格中已经出现的那样。您可以在以下位置看到它的作用:
函数实现如下所示:
另见:
<ui:composition ... xmlns:of="http://omnifaces.org/functions">
...
<li>Stack trace: <pre><code>#{of:printStackTrace(requestScope['javax.servlet.error.exception'])}</code></pre></li>
/**
* Print the stack trace of the given exception.
* @param exception The exception to print the stack trace for.
* @return The printed stack trace.
*/
public static String printStackTrace(Throwable exception) {
if (exception == null) {
return null;
}
StringWriter stringWriter = new StringWriter();
exception.printStackTrace(new PrintWriter(stringWriter, true));
return stringWriter.toString();
}