java web 配置异常拦截器

在web.xml中配置

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <error-page>
    <error-code>400</error-code>
    <location>/404.html</location>
  </error-page>
  <!-- 404 页面不存在错误 -->
  <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
  </error-page>
  <!-- 500 服务器内部错误 -->
  <error-page>
    <error-code>500</error-code>
    <location>/404.html</location>
  </error-page>
  <!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/404.html</location>
  </error-page>
  <!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
  <error-page>
    <exception-type>java.lang.NullPointerException</exception-type>
    <location>/404.html</location>
  </error-page>
  <error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/404.html</location>
  </error-page>
</web-app>

猜你喜欢

转载自blog.csdn.net/amazinga/article/details/105063553