【问题标题】:get some stack trace info into a custom tomcat error 500 page [duplicate]在自定义 tomcat 错误 500 页面中获取一些堆栈跟踪信息 [重复]
【发布时间】:2010-10-17 07:07:39
【问题描述】:

获取一些堆栈跟踪信息的最佳方式是什么,也许是 Execution.message 到我的自定义错误 500 页面上,带有 tomcat、spring、jsf?我只想显示异常的根本原因。

【问题讨论】:

  • 你想对堆栈跟踪做什么?在服务器日志中记录堆栈跟踪或向用户显示堆栈跟踪(在 XHTML/JSP 页面中)?

标签: spring jsf tomcat


【解决方案1】:

这是我在 Struts 中使用的 JSP 语法。您可能可以使用 JSf 来实现这个或类似的工作。

<!-- Get the exception object -->
<c:set var="exception" value="${requestScope['javax.servlet.error.exception']}"/>

<!-- Exception message(s) -->
<p>${exception.message}</p>
<p><c:if test="${not empty exception.cause.message}">${exception.cause.message}</c:if></p>

<!-- Stack trace -->
<jsp:scriptlet>
exception.printStackTrace(new java.io.PrintWriter(out));
</jsp:scriptlet>

【讨论】:

    【解决方案2】:

    我的解决方案是-

    使用this声明错误jsp页面为错误页面-

    <%@ page isErrorPage="true"%>
    

    稍后在同一个jsp页面中,您可以访问“异常”对象以将堆栈跟踪打印到您想要的任何位置。

    <%exception.printStackTrace();%>
    

    【讨论】:

    • 除非我添加了 isErrorPage 指令,否则页面会被常规错误页面替换。 +1
    猜你喜欢
    • 2015-11-19
    • 2017-10-14
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多