jsp错误页面的处理

局部的错误处理

  1,errorpage

    在错误页面指令page中声明errorpage="要显示的页面地址"

    在要显示的页面page中声明iserrorpage="true"(默认false 可以在jsp页面中输出exception.getMessage打印错误信息 前提iserrorpage是tue)

  2,设置全局错误处理页面(让错误全部跳转到指定页面)

    在web-xml中配置

        //500错误全部跳转到comm.jsp

        <error-page>

          <error-code>500</error-code>//错误类型

          <location>/comm/comm.jsp</location>//要跳转的页面地址(jsp页面)

        </error-page>

        //404错误全部跳转comm.html(静态的只有一个错误nofound)

        <error-page>

          <error-code>404</error-code>//错误类型

          <location>/comm/comm.html</location>//要跳转的页面地址(jsp页面)

        </error-page>

注意点

  优先执行errorpage的命令(要使用全局配置必须先删除errorpage)

原文地址:https://www.cnblogs.com/hello-liyb/p/7707819.html