在web.xml中配置异常处理页面
来源:互联网 发布:genbank数据库 编辑:程序博客网 时间:2024/06/05 07:57
通常为了给用户提供良好的人机接口,我们都会为整个web应用,提供处理异常或者 错误的通用页面,而这些通用页面需要在web.xml中进行配置,主要是两种方式:其一根据HTTP响应状态码;其二是根据异常类名进行配置。
格式如下:
<web-app>
<error-page>
<exception-type>完整的异常类名</exception-type>
<location>以”/”开头的异常处理页面路径</location>
</error-page>
<error-page>
<error-code>HTTP响应状态码</error-code>
<location>以”/”开头的异常处理页面路径</location>
</error-page>
</web-app>
//--------------------------------------------------------------//
<!-- 400错误 请求无效 -->
<error-page>
<error-code>400</error-code>
<location>/error.jsp</location>
</error-page>
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/error.jsp</location>
格式如下:
<web-app>
<error-page>
<exception-type>完整的异常类名</exception-type>
<location>以”/”开头的异常处理页面路径</location>
</error-page>
<error-page>
<error-code>HTTP响应状态码</error-code>
<location>以”/”开头的异常处理页面路径</location>
</error-page>
</web-app>
//--------------------------------------------------------------//
<!-- 400错误 请求无效 -->
<error-page>
<error-code>400</error-code>
<location>/error.jsp</location>
</error-page>
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/error.jsp</location>
</error-page>
对于无法跳转的解决:1.确保location属性中填写的错误页面是绝对路径2.确保error.jsp的大小>1024字节3.确保在error.jsp页面中添加<%@ page isErrorPage="true"%>注2:对于服务器端程序我们无法要求客户端去修改IE配置,因此流行的“在IE【工具】->【Internet选项】->【高级】中勾掉【显示友好http错误提示】”
这种解决办法一般不予考虑;不管在哪个配置文件中配置,如果不起作用,通常是由于错误文件太小引起的,error.jsp的大小要大于1024字节。
阅读全文
0 0
- 在web.xml中配置异常处理页面
- 在web.xml中配置异常处理页面
- 在web.xml中配置error页面
- J2EE中在web.xml异常页面跳转
- web.xml配置错误异常页面不起作用
- 在Web.xml中如何配置错误页面的拦截
- web.xml配置异常处理界面
- java web工程—在web.xml下配置异常处理界面
- 在web.xml配置错误信息跳转页面
- 在tomcat的web.xml中声明异常和错误页面
- web.xml中配置错误页面
- java web在web.xml中配置404,400,500页面
- JavaEE在web.xml中实现错误页面配置(error page)
- 在web.xml文件中配置的欢迎页面显示的时候报404的错误
- 在web.xml中配置error-page
- fckeditor在web.xml中配置
- 在web.xml中配置error-page
- 在web.xml中配置error-page
- 【LeetCode】路径系列
- Android定制:修改开机启动画面
- 四旋翼建模
- Visual Studio Code 使用 Typings 实现typescript的智能提示功能
- C/C++跨平台的的预编译宏
- 在web.xml中配置异常处理页面
- D3 坐标轴
- mac下sublime text 3 运行java文件
- MD5介绍、使用场景和使用中的注意事项
- 枚举类的写法与用法
- 3DES对称算法之双倍长密钥算法和三倍长密钥算法
- makefile里等号的意义
- Person Re-identification Datasets
- C语言之union共同体