Unable to capture exception on 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.stackT开发者_如何学JAVArace}" 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?
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 type javax.servlet.jsp.ErrorData
(see javadoc).
See J2EE tutorial for examples.
精彩评论