读书人

WEB error_page 施用

发布时间: 2012-07-04 19:33:54 作者: rapoo

WEB error_page 使用
1.在tomcat下配置

<error-page>
<error-code>500</error-code>
<location>/e500.jsp</location>
</error-page>

来 转发 500错误页面, 在Firefox下面可以正常显示错误页面, 但是在IE下面显示

  无法显示网页 您要访问的网页有问题,无法显示。 --------------------------------------------请尝试以下操作:打开 localhost:8280  主页,然后查找指向您感兴趣信息的链接。 单击 刷新按钮,或以后再试。单击 搜索,寻找 Internet 上的信息。 也可查看相关站点列表。 HTTP 500 - 内部服务器错误 Internet Explorer  


这是IE自身的设定导致的,经过百度,找到几个解决办法:


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



jsp页面获取异常信息:

<%
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");
out.println("<b>StatusCode:</b> " + status_code);
out.println("<br><b>Exception:</b>" + theException);
out.println("<br><b>ExceptionInfo:</b>" + theException+"<br><b>errorMessage:</b>"+exception.getMessage());
%>

读书人网 >Web前端

热点推荐