定义错误页面的位置,按错误码不同定位到不同的错误展示页面,系统中分为两类错误,第一类是404页面不存在的错误,另一类是服务器内部错误50x,对应的页面分别为404.jsp和error.jsp
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/error.jsp</location>
</error-page>
02)错误处理页面404.jsp--友好提示用户页面不存在,这个页面没什么特殊,核心是再该页面上给用户提示文案即可
<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>异常信息</title>
<style type="text/css">
body{ font-size:12px; color:#4d4b4b;}
</style>
</head>
<body>
<br><br><br><br><br><br>
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top" bgcolor="#D6E2F2">
<table cellpadding="0" cellspacing="0">
<tr>
<td>请求链接错误</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
您访问的页面不存在。
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
error.jsp--–对用户友好提示,将错误信息隐藏在页面中,可以通过CTRL+SHIFT+D键查看
<%@ page contentType="text/html; charset=UTF-8"%>
<%!String exceptionMsgForInner(Throwable e){
String ls_ErrMsg = e.getLocalizedMessage();
if (ls_ErrMsg == null) ls_ErrMsg = "";
ls_ErrMsg += "\r\n";
Throwable eCause = e.getCause();
if (eCause == null){
for (int ii = 0;ii < e.getStackTrace().length;ii++){
ls_ErrMsg += e.getStackTrace()[ii].toString() + "\r\n";
}
} else{
ls_ErrMsg += exceptionMsgForInner(eCause);
}
return ls_ErrMsg.trim();
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>异常信息</title>
<style type="text/css">
body{ font-size:12px; color:#4d4b4b;}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function dokeydown(){
if (event.ctrlKey && event.shiftKey && event.keyCode==68){
var obj=document.getElementById("divexception");
if (obj.style.display.toLowerCase()=="none"){
obj.style.display="block";
}else{
obj.style.display="none";
}
return false;
}
}
window.document.attachEvent('onkeydown', dokeydown);
//-->
</SCRIPT>
</head>
<body>
<br><br><br><br><br><br>
<table cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top" bgcolor="#D6E2F2">
<table cellpadding="0" cellspacing="0">
<tr>
<td>异常信息</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
系统异常,请联系管理员。
</td>
</tr>
</table>
</td>
</tr>
<tr><td>
<div align=center id=divexception>
<TEXTAREA ROWS="8" COLS="100">
<%
Exception ex = (Exception) request.getAttribute("javax.servlet.error.exception");
out.println(exceptionMsgForInner(ex));
%>
</TEXTAREA>
<div>
</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>