web.xml配置错误错误页面,及输出错误信息
2018-01-18 20:41
447 查看
1.需要在web.xml中配置相关信息[html] view plain copy<!-- 默认的错误处理页面 -->
<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>
<!-- 仅仅在调试的时候注视掉,在正式部署的时候不能注释 -->
<!-- 这样配置也是可以的,表示发生500错误的时候,转到500.jsp页面处理。 -->
<error-page>
<error-code>500</error-code>
<location>/500.html</location>
</error-page>
<!-- 这样的配置表示如果jsp页面或者servlet发生java.lang.Exception类型(当然包含子类)的异常就会转到500.jsp页面处理。 -->
<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>
<!--
当error-code和exception-type都配置时,exception-type配置的页面优先级高
及出现500错误,发生异常Exception时会跳转到500.jsp
-->
2.如果配置是html时,不用另做配置 如果配置是Jsp时,需要把isErrorPage设置为true, 及<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%>3.获取异常信息及输出[html] view plain copy<%@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>
<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>
<!-- 仅仅在调试的时候注视掉,在正式部署的时候不能注释 -->
<!-- 这样配置也是可以的,表示发生500错误的时候,转到500.jsp页面处理。 -->
<error-page>
<error-code>500</error-code>
<location>/500.html</location>
</error-page>
<!-- 这样的配置表示如果jsp页面或者servlet发生java.lang.Exception类型(当然包含子类)的异常就会转到500.jsp页面处理。 -->
<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>
<!--
当error-code和exception-type都配置时,exception-type配置的页面优先级高
及出现500错误,发生异常Exception时会跳转到500.jsp
-->
2.如果配置是html时,不用另做配置 如果配置是Jsp时,需要把isErrorPage设置为true, 及<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%>3.获取异常信息及输出[html] view plain copy<%@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>
相关文章推荐
- web.xml配置错误页面,及输出错误信息
- web.xml配置错误页面,及输出错误信息
- web.xml配置错误页面,及输出错误信息
- 在web.xml配置错误信息跳转页面
- web.xml 错误页面的配置
- tomcat 可以在web.xml当中配置404 自定义错误页面
- JSP——web.xml中配置错误页面
- web.xml中配置错误页面不能跳转
- web.xml配置错误页面
- WEB.XML error-page 配置错误页面
- JavaEE在web.xml中实现错误页面配置(error page)
- 关于web.xml中配置404错误跳转页面 在ie不能显示自定义错误页面的问题
- 关于web.xml中配置404错误跳转页面 在ie不能显示自定义错误页面的问题
- IIS错误信息:HTTP 错误 401.3 - Unauthorized 由于 Web 服务器上此资源的访问控制列表(ACL)配置或加密设置,您无权查看此目录或页面
- 在web.xml文件中配置的欢迎页面显示的时候报404的错误
- web.xml中DispatcherServlet的url-pattern配置错误导致JSP页面在浏览器中显示为源码
- web.xml配置错误页面
- web.xml配置详解之欢迎页面和错误页面
- web.xml配置错误页面转发
- web.xml中配置错误页面