web.xml配置错误页面,及输出错误信息
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>
- <!-- 仅仅在调试的时候注视掉,在正式部署的时候不能注释 -->
- <!-- 这样配置也是可以的,表示发生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
- -->
<!-- 默认的错误处理页面 -->
<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.获取异常信息及输出
- <%@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>
<%@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文件中的7个错误的安全配置
web.xml文件中的7个错误的安全配置 关于Java的web.xml文件中配置认证和授权有大 量 的 文章.本文不再去重新讲解如何配置角色.保护web资源和设置不同类型的认证,让我们来看看web.x ...
- tomcat web.xml 配置
1<web-app> 2<error-page> 3<error-code>404</error-code> 4<location>/Not ...
- Web.xml配置详解(转)
Web.xml配置详解 Posted on 2010-09-02 14:09 chinaifne 阅读(295105) 评论(16) 编辑 收藏 1 定义头和根元素 部署描述符文件就像所有XML文件一 ...
- java web.xml配置详解
1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...
- Spring MVC的web.xml配置详解(转)
出处http://blog.csdn.net/u010796790 1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在w ...
- web.xml 配置介绍
这个不是原创,有点早了,具体从哪里来的已经记不得了.但是东西是实实在在的. 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<c ...
- web.xml配置以及一些详解
web.xml的根元素定义如下所示(代表当前使用哪个模版): <?xml version="1.0" encoding="UTF-8"?> < ...
- Spring mvc的web.xml配置详解
1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在web.xml配置监听器ContextLoaderListener(l ...
- Spring 及 SpringMVC的web.xml配置详解
出处http://blog.csdn.net/u010796790 1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在w ...
- 160329(二)、web.xml配置详解
1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...
随机推荐
- MongoDB wiredTiger存储引擎下的存储方式LSM和B-Tree比较
前段时间做拦截件监控的时候把拦截件生命期存入mongodb,因生命期有各种变化,因此对此表的更新写操作非常多,老大给我看了一篇文章,才知道mongodb已经支持lsm存储方式了. 原文如连接:http ...
- iis支持asp.net4.0的注册命令使用方法及部署网站注意事项
如果没有按照正常的先装iis后装.net的顺序,可以使用以下命令重新注册一下,这样iis就可以支持asp.net 4.0了 32位的Windows: 1. 运行->cmd,打开窗口时请以管理 ...
- (转)MySQL open_files_limit相关设置
http://www.cnblogs.com/zhoujinyi/archive/2013/01/31/2883433.html---------------------------MySQL ope ...
- android 小工具:pc 上用 curl 命令打开手机浏览器,浏览指定网址
测试 API 时或其它情况经常需要在手机浏览器中输入 url 一长串的 url 输起来真是麻烦 AirDroid 很强大也不用数据线,但有时老断开连接,不是很爽.发到手机 qq 吧还得手动粘贴 所以自 ...
- 我Java学习时的模样(三)
读Java源码 平常使用Java的时候,那些集合类使用起来很顺手,但是有没有想过这些集合内部的实现原理是怎样的,它的添加移除都有哪些操作? 有了一些工作经验之后,必须要读一读Java包中的源码,需要知 ...
- Gradient descent and others
Batch gradient descent Procedure 在循环中跌倒公式\(\theta_j:=\theta_j-\alpha{1\over{m}}\sum_{i=1}^m(h_{\thet ...
- [转]error MSB4018: The "GenerateResource" task failed unexpectedly
本文转自:https://github.com/Microsoft/msbuild/issues/364 After uninstall Visual Studio 2015 Update 1 RC ...
- Linux文件上传下载sz 和 rz 命令
windows系统和linux系统之间文件上传和下载用到 rz 和 sz 命令.rz: 上传文件sz:下载文件 先检查是否安装rz,sz模块 安装rz,sz 模块yum search sz安装yum ...
- 用m2eclipse创建Maven项目时报错
Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:p ...
- Win10自带Ubuntu子系统下Mysql安装踩坑记录
linux系统为win10自带Ubuntu子系统 错误的安装过程 我按照一般的方法安装mysql,安装步骤如下 1.升级源 $ sudo apt-get update 2.安装mysql $ sudo ...