JSP page指令 errorPage属性和isErrorPage属性示例
- page-err.jsp页面
page指令errorPage属性,指定页面出错时将转向的错误处理页面,此页面的isErrorPage属性默认为false
<%-- page指令errorPage属性,指定页面出错时将转向的错误处理页面,此页面的isErrorPage属性默认为false --%>
<%@ page contentType="text/html;charset=UTF-8" errorPage="error.jsp" %>
<html>
<head>
<title>JSP 基础语法</title>
</head>
<body>
<h1>page 指令 errorPage属性示例页面</h1>
<%
String varStr="It can't be.";
int x=Integer.parseInt(varStr);
%>
</body>
</html>
- error.jsp页面
错误处理页面,isErrorPage属性为true,其他网页出错时转向本页面
<%--错误处理页面,isErrorPage属性为true,其他网页出错时转向本页面 --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>错误处理页面</h1>
<h2>出错了。</h2>
</body>
</html>
注意:在IE浏览器中(5.0以及以上版本),默认忽略服务器错误提示页面,而显示IE自定义的错误页面
解决方案:
- 设置IE浏览器的选项工具->Internet选项->高级->显示友好HTTP错误消息,取消这个选项的选择。
- 在页面中添加下面的代码,设置错误处理页面的页面状态为正常,告诉IE浏览器这不是一个服务器错误。
<%
response.setStatus(200);//200=HttpServletResponse.SC_ok
%>- 把错误页面做得大一点,几百KB以上(价格div,display设为none即可),就可以显示错误页面。