1、总览
2、application.properties
spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp
#关闭whitelabel Error page
server.error.whitelabel.enabled=false
#默认never,无法输出trace
server.error.include-stacktrace=always
3、controller
@Controller
public class MyController {
@RequestMapping("/")
public String handler (Model model) {
throw new RuntimeException("test exception");
}
}
4、error.jsp
因为spring boot 提供了一个默认的mapping:/error,因此,我们起的错误jsp页面的文件名为error.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<html>
<head>
<style>
table td{
vertical-align:top;
border:solid 1px #888;
padding:10px;
}
</style>
</head>
<body>
<h1>My Error Page</h1>
<table>
<tr>
<td>Date</td>
<td>${timestamp}</td>
</tr>
<tr>
<td>Error</td>
<td>${error}</td>
</tr>
<tr>
<td>Status</td>
<td>${status}</td>
</tr>
<tr>
<td>Message</td>
<td>${message}</td>
</tr>
<tr>
<td>Exception</td>
<td>${exception}</td>
</tr>
<tr>
<td>Trace</td>
<td>
<pre>${trace}</pre>
</td>
</tr>
</table>
</body>
</html>
5、执行
当执行http://localhost:8080/时,报错:
当执行不存在资源时: