web.xml配置详解之欢迎页面和错误页面

<!-- 应用的欢迎页面  采用list的方式罗列欢迎页面,

系统会从第一个找到最后一个,找到了文件就不继续往下找了。优先显示前边的。

-->

    <welcome-file-list>

       <welcome-file>index.jsp</welcome-file>

       <welcome-file>login.jsp</welcome-file>

       <welcome-file>index.html</welcome-file>

       <welcome-file>index.htm</welcome-file>

       <welcome-file>default.html</welcome-file>

       <welcome-file>default.htm</welcome-file>

       <welcome-file>default.jsp</welcome-file>

    </welcome-file-list>

    <!-- 通过上边welcome-file-lis的配置:我们的应用的欢迎界面或者叫默认界面就是index.jsp,如果index.jsp没找到的话

    就接着往下找:login.jsp,index.html.... -->

   

    <!-- 配置错误页面

       error-page标签用来配置档应用出现指定错误码的错误时候,有哪个页面来处理这个错误,而不是给用户

           显示系统的错误信息。子标签:

       error-code:系统错误码

       location:应用系统中的处理错误页面。

    -->

    <error-page>

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

       <location>/common/404.html</location>

       <!-- 表示当系统发生404就是不存在请求地址的错误的时候,页面跳转到404.html页面。 -->

    </error-page>

    <error-page>

       <error-code>500</error-code>

       <location>/common/error.jsp</location>

       <!-- 表示当系统发生500也就是操作异常错误的时候,页面跳转到error.jsp页面。 -->

    </error-page>

    <error-page>

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

       <location>/common/error.jsp</location>

       <!-- 表示当系统发生空指针异常错误的时候,页面跳转到error.html页面。 -->

    </error-page>

    <!-- 通过上边对error-apge的配置:当我们系统的系统发生404错误的时候,页面调准到404.html,

    当页面发生服务器错我或者空指针错误的时候,页面跳转到error.html -->

</web-app>

 此文转载于:http://angrycoder.iteye.com/blog/919375

原文地址:https://www.cnblogs.com/liuyq/p/3664195.html