- Mastering Spring 5.0
- Ranga Rao Karanam
- 81字
- 2021-07-02 22:12:19
The error view
Whenever an exception happens, ExceptionController redirects the user to the ExceptionController spring-mvc-error view after populating the model with exception details. The following snippet shows the complete jsp /WEB-INF/views/common/spring-mvc-error.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page isErrorPage="true"%>
<h1>Error Page</h1>
URL: ${url}
<BR />
Exception: ${exception.message}
<c:forEach items="${exception.stackTrace}"
var="exceptionStackTrace">
${exceptionStackTrace}
</c:forEach>
Important things to note are as follows:
- URL: ${url}: Shows the URL from the model.
- Exception: ${exception.message}: Displays the exception message. The exception is populated into the model from ExceptionController.
- forEach around ${exceptionStackTrace}: Displays the stack trace from exception handling specific to ExceptionController.