web.xml配置404和500错误及异常

Web.xml一般的错误及异常配置:

 <!-- 配置错误处理 -->

    <error-page>

       <error-code>404</error-code>

       <location>/404.html</location>

    </error-page>

    <error-page>

       <error-code>505</error-code>                             

       <location>/505.html</location>

    </error-page>

    <!-- 配置异常处理 -->

    <error-page>

       <exception-type>javax.servle.ServletException</exception-type>

       <location>/error.html</location>

    </error-page>

    <error-page>

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

       <location>/error.html</location>

    </error-page>

异常:

当访问一个action或是servlet的时,可能会出现异常,

struts2中web.xml配置:

<default-action-ref name="pagenotfound"></default-action-ref>?
  <action name="pagenotfound"> 
    <result>/pagenotfound.html</result>?
  </action>
servlet 中web.xml配置:

<error-page>
   <exception-type>javax.servle.ServletException</exception-type>
   <location>/error.html</location>
</error-page>

你可能感兴趣的:(异常处理,web.xml,异常,404,500)