web.xml配置出错页面

  配置出错页面可以有两种方式

    1.page指令

      <@ page errorPage="/errors/error.jsp"/>

         这个只能作用于当前的jsp页面

    2.web.xml

      ~.exception-type:依据错误的类型

      ~.exception-code:依据网页打开状态

      <error-page>  

         <exception-type>java.lang.ArithmeticException</exception-type>

         <location>/errors/arithmentException.jsp</location>

      </error-page>

      这个配置是全局配置,出现这个错误时直接调用这个页面显示给用户,不会给用户拋异常,但是arithmentException.jsp,这个jsp页面大小不能超过1k

      <error-page>  

         <exception-code>java.lang.ArithmeticException</exception-code>

         <location>/errors/404.jsp</location>

      </error-page>

注意我们这里用的这些错误的页面,最好要用page指令的isErrorPage=true,这样的话,这个页面在执行的时候会创建给一个exception对想,我们可以通过这个对象进行错误的捕捉,以便于我们后期的维护。

    查看jsp翻译后的路径,jsp就是servlet嘛,所以它存在apache-tomcat-6.0.35workCatalinalocalhost这个里面

如果有使用请标明来源:http://www.cnblogs.com/duwenlei/
原文地址:https://www.cnblogs.com/duwenlei/p/3498026.html