无法捕获错误页面上的异常
我正在尝试打印 jsp 页面上的异常堆栈跟踪。但是,隐式异常对象似乎没有被填充。
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:spring="http://www.springframework.org/tags"
xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.page isErrorPage="true" />
<spring:message var="title" code="error_uncaughtexception_title"/>
<h2>${fn:escapeXml(title)}</h2>
<p>
<spring:message code="error_uncaughtexception_problemdescription"/>
</p>
<c:if test="${not empty exception}">
<p>
<h4>
<spring:message code="exception_details"/>
</h4>
<spring:message var="message" code="exception_message"/>
<c:out value="${exception.localizedMessage}"/>
<spring:message var="stacktrace" code="exception_stacktrace"/>
<c:forEach items="${exception.stackTrace}" var="trace">
<c:out value="${trace}"/>
<br/>
</c:forEach>
</p>
</c:if>
该页面在 web.xml 中正确配置:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/uncaughtException</location>
</error-page>
对我缺少的内容有什么猜测吗?
I'm trying to print out the an exception stack trace on a jsp page. However, the implicit exception object doesn't seem to be populated.
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:spring="http://www.springframework.org/tags"
xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.page isErrorPage="true" />
<spring:message var="title" code="error_uncaughtexception_title"/>
<h2>${fn:escapeXml(title)}</h2>
<p>
<spring:message code="error_uncaughtexception_problemdescription"/>
</p>
<c:if test="${not empty exception}">
<p>
<h4>
<spring:message code="exception_details"/>
</h4>
<spring:message var="message" code="exception_message"/>
<c:out value="${exception.localizedMessage}"/>
<spring:message var="stacktrace" code="exception_stacktrace"/>
<c:forEach items="${exception.stackTrace}" var="trace">
<c:out value="${trace}"/>
<br/>
</c:forEach>
</p>
</c:if>
The page is properly configured in web.xml:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/uncaughtException</location>
</error-page>
Any guesses as to what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
exception
隐式对象可用作页面变量(即对于 scriptlet),但不能用作 EL 引用。您可以使用
${pageContext.errorData}
表达式访问异常状态(请参阅 docs),它是javax.servlet.jsp.ErrorData
类型的对象(请参阅 javadoc)。有关示例,请参阅 J2EE 教程。
The
exception
implicit object is available as a page variable (i.e. for scriptlets) but is not available as an EL reference.You can access the exception state using the
${pageContext.errorData}
expression (see docs), which is an object of typejavax.servlet.jsp.ErrorData
(see javadoc).See J2EE tutorial for examples.