web.xml:
这种写法在ie浏览器下有问题.
必须在IE【工具】->【Internet选项】->【高级】中勾掉【显示友好http错误提示】;
但我们不能控制客户的浏览器
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error500.jsp</location>
</error-page>
----------------------------
正确的:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
error.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*" errorPage="error.jsp"%>
<html>
<head>
<title>自定义的错误页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body marginwidth="0" leftmargin="0" bgcolor="ffffff">
<table width="90%">
<tbody>
<tr>
<td width="98%">
这是自定义的错误页
<hr> </td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<%
int status_code = -1;
String exception_info = null;
Exception theException = null;
status_code = ((Integer) request.getAttribute("javax.servlet.error.status_code"));
exception_info = (String) request.getAttribute("javax.servlet.error.message");
theException = (Exception) request.getAttribute("javax.servlet.error.exception_type");
if(status_code==404)
response.sendRedirect("error404.jsp");
if(status_code==500)
response.sendRedirect("error500.jsp");
out.println("<br><b>StatusCode:</b> " + status_code);
out.println("<br><b>Exception:</b>" + exception_info);
%> </TD>
</TR>
<TD>
<HR> </TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
分享到:
相关推荐
自定义错误页面.rar
显示自定义错误页面,用户自定义
该资源是我的博文《Spring Boot自定义错误页面》的关联资源,博文链接:http://blog.csdn.net/github_32521685/article/details/50198467
自定义错误页面111111111
本文实例讲述了ThinkPHP中自定义错误页面和提示页面的方法。分享给大家供大家参考。具体实现方法如下: 在ThinkPHP中有两个方法时提示错误页面 _404(‘错误信息’,’跳转的地址’);halt(‘提示信息’); 这两个函数都...
404404 错误页面错误页面 自定义页面自定义页面 页面页面
360安全卫士如何关闭自定义错误页面.docx
python flask 自定义错误页面404.html源代码 及图片 代码
IIS配置:自定义错误页面&不允许访问目录 访问不存在目录、访问目录、访问不存在页面自动跳转
【ASP.NET编程知识】ASP.NET MVC自定义错误页面真的简单吗.docx
主要介绍了在Tomcat中配置404自定义错误页面全解,需要的朋友可以参考下
python 23、FLASK框架 2-11_11.自定义错误页面.mp4
主要介绍了Nuxt默认模板、默认布局和自定义错误页面的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
apache自定义错误页面 针对Apache Web服务器的自定义错误页面模板(针对移动设备进行了优化,CSS3) 指示 将所有文件复制到服务器的根目录 将这些行添加到您的.htaccess文件中: #Custom Error pages ...
NULL 博文链接:https://fanshuyao.iteye.com/blog/2414828
asp.net 异常处理跳转自定义404,500页面Demo实现,想要学习的可以看看,通过Application_Error 中拦截异常
自定义错误演示展示如何在 MVC 5 中显示自定义错误页面
这种写法在ie浏览器下有问题. <error-page> <error-code>404 </error-code> <location>/error404.jsp </location> </error-page> <error-page> <error-code>500 </error-code> <location>/error500.jsp ...