1.需要在web.xml中配置相关信息
-
-
<error-page>
-
<error-code>403</error-code>
-
<location>/403.html</location>
-
</error-page>
-
<error-page>
-
<error-code>404</error-code>
-
<location>/404.html</location>
-
</error-page>
-
-
-
<error-page>
-
<error-code>500</error-code>
-
<location>/500.html</location>
-
</error-page>
-
-
-
<error-page>
-
<exception-type>java.lang.Exception</exception-type>
-
<location>/500.jsp</location>
-
</error-page>
-
-
<error-page>
-
<exception-type>java.lang.Throwable</exception-type>
-
<location>/500.jsp</location>
-
</error-page>
-
2.如果配置是html时,不用另做配置
如果配置是Jsp时,需要把isErrorPage设置为true,
及<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%>
3.获取异常信息及输出
点击(此处)折叠或打开
-
<%@page import="java.io.PrintStream"%>
-
<%@page import="java.io.ByteArrayOutputStream"%>
-
<%@ include file="WEB-INF/views/includes/tags.jsp"%>
-
<%@ page language="java" contentType="text/html; charset=UTF-8"
-
pageEncoding="UTF-8" isErrorPage="true"%>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<title>500 服务器内部错误</title>
-
</head>
-
<body>
-
<div class="ui-alert-panel">
-
<h1>服务器内部错误</h1>
-
<p>处理您的请求时发生错误!请确认您通过正确途径操作。</p>
-
</div>
-
<div style="display:none;">
-
<% //此处输出异常信息
-
exception.printStackTrace();
-
-
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
-
exception.printStackTrace(new PrintStream(ostr));
-
out.print(ostr);
-
%>
-
</div>
-
</body>
-
</html>
阅读(2519) | 评论(0) | 转发(0) |