配置WEB錯誤頁面

  專案執行時,難免會出現錯誤,這些錯誤我們不可以也不方便直接讓使用者看到,所以配置錯誤頁面是非常必要的。

  一下是專案的Web.xml文件,在最下方陰影部分是配置錯誤介面。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0" metadata-complete="false">

    <display-name>esp-web</display-name>

    <!-- Spring配置文件開始 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
             classpath:spring-common.xml,
             classpath:spring-config.xml
         </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Spring配置文件結束 -->

    <!-- 可以使用RequestContextHolder.currentRequestAttributes() 獲取到請求的attr -->
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <!-- 設定servlet編碼開始 -->
    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- 設定servlet編碼結束 -->

    <!-- 記錄訪問日誌,比如審計之類的可用 -->
    <filter>
        <filter-name>AccessLogFilter</filter-name>
        <filter-class>com.pcitc.common.web.filter.AccessLogFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>blackListURL</param-name>
            <param-value>/static/**,*.js,*.css,*.jpg,*.gif,*.png,*.ico,/admin/monitor/druid/**</param-value>
        </init-param>
        <init-param>
            <param-name>whiteListURL</param-name>
            <param-value>/**</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>AccessLogFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <!-- shiro 安全過濾器 -->
    <!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->
    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <!-- Make sure any request you want accessible to Shiro is filtered. /* 
        catches all -->
    <!-- requests. Usually this filter mapping is defined first (before all 
        others) to -->
    <!-- ensure that Shiro works in subsequent filters in the filter chain: -->
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>


    <!-- 驗證碼過濾器需要放到Shiro之後 因為Shiro將包裝HttpSession 如果不 可能造成兩次的sesison id 不一樣 -->
    <filter>
        <filter-name>JCaptchaFilter</filter-name>
        <filter-class>com.pcitc.common.web.jcaptcha.JCaptchaFilter</filter-class>
        <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
        <filter-name>JCaptchaFilter</filter-name>
        <url-pattern>/jcaptcha.jpg</url-pattern>
    </filter-mapping>

    <!--druid 監控 -->
    <filter>
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>exclusions</param-name>
            <param-value>/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
        </init-param>
        <init-param>
            <param-name>principalSessionName</param-name>
            <param-value>username</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- druid監控 -->
    <servlet>
        <servlet-name>DruidStatView</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView</servlet-name>
        <url-pattern>/admin/monitor/druid/*</url-pattern>
    </servlet-mapping>


    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!-- 自定義tld標籤 -->
    <jsp-config>
        <taglib>
            <taglib-uri>http://mytag.sf.net</taglib-uri>
            <taglib-location>/WEB-INF/mytag.tld</taglib-location>
        </taglib>
    </jsp-config>

    <!-- 錯誤頁面對映 -->
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/jsp/error/error.jsp</location>
    </error-page>
    <error-page>
        <error-code>400</error-code>
        <location>/WEB-INF/jsp/error/error.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/jsp/error/error.jsp</location>
    </error-page>
    <error-page>
        <error-code>503</error-code>
        <location>/WEB-INF/jsp/error/error.jsp</location>
    </error-page>
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/WEB-INF/jsp/error/error.jsp</location>
    </error-page>

    <!--如果 發現報 該錯誤 No mapping found for HTTP request with URI 加入下mapping <servlet-mapping> 
        <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping -->

</web-app>

 

關鍵詞:filter param name error servlet web mapping value class pattern

相關推薦:

SpringCloud統一配置筆記

2、Qt Project之滑鼠事件監控

SpringBoot (一)

許可權管理demo-pom.xml

zabbix自定義模板——監控TCP連線狀態

ssm整合的pom.xml依賴

020-pom.xml配置文件模板

spring-CXF-maven

HTML語言基礎

JS表格分頁(封裝版)