您的位置:首页 > Web前端 > JavaScript

JSP 中的 Error Page

2016-02-15 18:22 603 查看

在 web.xml 中配置

<error-page>
<error-code>404</error-code>
<location>/WEB-INF/pages/error/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/pages/error/500.jsp</location>
</error-page>


有两个要点:

把 jsp 放在 WEB-INF 中可以使其不能直接被访问。

可以用 error-code 或者 exception type 来找示错误信息。

书写 error page

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台错误</title>

<link rel="stylesheet" href="static/Endless1.5.1/bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3><a href="/BC3/"><img alt="真是抱歉!" src="static/img/sorry.png" style="width:80px;"></a><span class="label label-default">非常抱歉,后台出错了!点我返回...</span> </h3>

<br>
<table class="table">
<tr>
<td width="20%"><b>错误:</b></td>
<td>${pageContext.exception}</td>
</tr>
<tr>
<td><b>URI:</b></td>
<td>${pageContext.errorData.requestURI}</td>
</tr>
<tr>
<td><b>状态代码:</b></td>
<td>${pageContext.errorData.statusCode}</td>
</tr>
<tr>
<td><b>错误追溯:</b></td>
<td>
<c:forEach var="trace" items="${pageContext.exception.stackTrace}">
<p>${trace}</p>
</c:forEach>
</td>
</tr>
</table>
</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: