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>

發佈了32 篇原創文章 · 獲贊 17 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章