无法在错误页面上捕获异常

Kar*_*ran 3 java jsp tomcat spring-mvc

我正在尝试在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>
Run Code Online (Sandbox Code Playgroud)

该页面在web.xml中正确配置:

 <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/uncaughtException</location>
    </error-page>
Run Code Online (Sandbox Code Playgroud)

有什么猜测我错过了什么?

ska*_*man 5

exception隐式对象可作为页面变量(即,对于小脚本),但不可用作为EL参考.

您可以使用${pageContext.errorData}表达式(请参阅docs)访问异常状态,该表达式是类型的对象javax.servlet.jsp.ErrorData(请参阅javadoc).

有关示例,请参阅J2EE教程.