错误页面的处理

有时候为了页面友好性,错误页面,特别是500页面不能显示出来给客户看,但是对于我们开发人员来说这信息在排查问题时候尤为重要;首先在web.xml里面配置错误页面跳转的方式 

     <error-page>
      <error-code>404</error-code>
      <location>/5001.jsp</location>
    </error-page>
    <error-page>
      <error-code>500</error-code>
      <location>/5001.jsp</location>
    </error-page>
捕获这两种404和500的错误页面,当然还有其他的,可以针对自己的工程和业务去增加;

然后到5001.jsp这个页面

在jsp页面加上这个<%@ page language="java" contentType="text/html; charset=utf-8" isErrorPage="true"%>
<%@ page language="java" contentType="text/html; charset=utf-8" isErrorPage="true"%>
isErrorPage="true"

然后把错误转成文本字符串方式

<%

StringWriter sw = new StringWriter(); 
PrintWriter pw = new PrintWriter(sw); 
exception.printStackTrace(pw); 
%>
<%=sw.toString() %>

猜你喜欢

转载自fqg05.iteye.com/blog/2168598