读书人

Tomcat Error Page配置 与 Error Page

发布时间: 2012-08-26 16:48:05 作者: rapoo

Tomcat Error Page配置 与 Error Page在IE下不能转发的问题

?

<html>
<head><title>出现错误</title></head>
<body>
???? <H1>错误:</H1><%=exception%>
???? <H2>错误内容:</H2>
???? <%
???????? exception.printStackTrace(response.getWriter());
???? %>
</body>
</html>
因为这个页面调用了exception内置对象,所以isErrorPage必须为true。
3.不仅可以根据html的错误代码来条转页面,也可以按异常类型来进行跳转,例如:
<error-page>
??? <exception-type>javax.servlet.ServletException</exception-type>
??? <location>/errorhandler.jsp</location>
</error-page>
不仅可以使用jsp内置exception对象来取得异常,也可以取得request中的attribute。例如:
<%@Page contentType="text/html;charset=Big5" isErrorPage="true"%>
<html>
<head><title>错误信息</title></head>
<body>
???? 错误码: <%=request.getAttribute("javax.servlet.error.status_code")%> <br>
???? 信息: <%=request.getAttribute("javax.servlet.error.message")%> <br>
???? 异常: <%=request.getAttribute("javax.servlet.error.exception_type")%> <br>
</body>
</html>

二: Error Page在IE下不能转发的问题

这是IE自身的设定导致的,经过百度,找到几个解决办法:????
1, IE设定?? 工具-->Internet选项-->高级--->显示http友好错误信息(取消选择) , 这样就可以了
2, 设置指定错误页页状态为正常,来告诉IE这不是一个服务器错误, 从而不显示IE的自定义错误页?
<%
??? response.setStatus(200); // 200 = HttpServletResponse.SC_OK
%>
3, 把错误页做大一点,弄个几百K 就可以显示错误页面 (加一个div块,display设为none就可以了),这个问题比较奇怪.

读书人网 >Ruby Rails

热点推荐