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>