JSP中统一错误信息输出

一、在JSP页面中
 1、在jsp页面中加入<%@ page errorPage="error.jsp"%>
     指定错误处理页面为error.jsp 

 2、在error.jsp中将错误信息输出显示
   <%@ page isErrorPage="true" import="java.io.*"%>
   <%=exception.getMessage()%><br>
  <%=exception.getLocalizedMessage()%>
  <%
   StringWriter sw=new StringWriter();
   PrintWriter pw=new PrintWriter(sw);
   exception.printStackTrace(pw);
   out.print(sw);
  %>

二、在web.xml配置文件中
<error-page>
    <error-code>404</error-code>
    <location>/pageNotFound.htm</location>
  </error-page>
  <error-page>
    <error-code>505</error-code>
    <location>/internalError.htm</location>
  </error-page>

  <error-page>
    <exception-type>java.lang.NumberFormatException</exception-type>
    <location>/internalError.htm</location>
  </error-page>

你可能感兴趣的:(jsp,import)