web.xml中错误页面的配置
原文:https://blog.csdn.net/bao19901210/article/details/23370407
1.错误页面是html时的配置
<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>
2.错误页面时jsp时的配置
<error-page> <error-code>500</error-code> <location>/500.jsp</location> </error-page>
3.如果错误页面是jsp时,需要把该jsp文件的isErrorPage属性设置为true
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%>
4.jsp错误页面内如何获取异常信息并输出
<%@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" "http://www.w3.org/TR/html4/loose.dtd"> <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>