JSP 中的 Error Page

在 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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值