Spring MVC +Mybatis + Maven 配置之web.xml配置__spinrg

來源:互聯網
上載者:User
       web.xml作用,以及web容器執行順序          每個網站一般都有一個web.xml,被用來初始化配置資訊,但是又不是必須的。web.xml是web容器首先讀取的檔案。web容器執行的順序是:
        1、啟動一個WEB項目的時候,WEB容器會去讀取它的設定檔web.xml,讀取<listener>和<context-param>兩個結點。
        2、容器建立一個ServletContext(servlet上下文),這個web項目的所有部分都將共用這個上下文。
        3、容器將<context-param>轉換為索引值對,並交給servletContext。

        4、容器建立<listener>中的類執行個體,建立監聽器。

        web.xml中配置執行順序ServletContext-> context-param ->listener -> filter -> servlet        web.xml中配置的項目內容 定義log4j設定檔的載入 定義應用程式的初始化 定義Spring MVC 配置 定義防止spring記憶體溢出配置
定義請求的字元集過濾器 定義整個應用程式訪問的預設頁 定義jstl自訂函數檔案配置 定義驗證碼載入配置 定義載入dwr配置
定義session有效期間限配置 定義自訂預設404、500頁面 定義應用程式是否支援分布式部署配置 定義mybatis配置 定義上下文監聽器配置         完整的web.xml配置內容

    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath*:/spring/spring-content.xml</param-value>    </context-param>    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>    <listener>          <listener-class>              org.springframework.web.context.request.RequestContextListener          </listener-class>      </listener>     <!--log4j設定檔載入-->    <context-param>          <param-name>log4jConfigLocation</param-name>          <param-value>classpath:setup/log4j.xml</param-value>      </context-param>            <!--啟動Log4jConfigListener監聽器  每60s監聽一次log4j.xml設定檔的變化-->    <context-param>          <param-name>log4jRefreshInterval</param-name>          <param-value>60000</param-value>      </context-param>      <listener>          <listener-class>              org.springframework.web.util.Log4jConfigListener          </listener-class>      </listener>      <!--log4j.properites載入Log4j -->    <context-param>        <param-name>log4jConfigLocation</param-name>        <param-value>classpath:log/console.properties</param-value>    </context-param>    <context-param>        <param-name>log4jRefreshInterval</param-name>        <!--Spring預設重新整理Log4j設定檔的間隔,單位為millisecond -->        <param-value>60000</param-value>    </context-param>    <listener>        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>    </listener>    <!-- logback配置    -->    <context-param>        <param-name>logbackConfigLocation</param-name>        <param-value>classpath:logback.xml</param-value>     </context-param>    <listener>        <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>    </listener>    <!--啟動應用程式初始化監聽器 ApplicationInitListener-->    <listener>        <listener-class>com.rrtong.frame.ApplicationInitListener</listener-class>    </listener>    <!-- Spring MVC 相關配置 -->    <servlet>        <servlet-name>Dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>    <param-name>contextConfigLocation</param-name>            <param-value>classpath:setup/applicationContext-mvc.xml</param-value></init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <!-- 防止spring記憶體溢出監聽器 -->    <listener>        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>    </listener>    <servlet-mapping>        <servlet-name>Dispatcher</servlet-name><url-pattern>*.do</url-pattern>    </servlet-mapping>    <!-- 定義過濾器 -->    <filter><filter-name>Set Character Encoding</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>    <init-param><param-name>encoding</param-name><param-value>utf-8</param-value>    </init-param>    </filter>    <filter-mapping><filter-name>Set Character Encoding</filter-name><url-pattern>*.do</url-pattern>    </filter-mapping>    <!-- 定義預設頁面 -->    <welcome-file-list>        <welcome-file>index.jsp</welcome-file>    </welcome-file-list>    <!-- 自訂jstl標籤函數 -->    <jsp-config>        <taglib>    <taglib-uri>http://tags.rrtong.com/pj</taglib-uri>    <taglib-location>/WEB-INF/jstl/custom.tld</taglib-location></taglib><taglib>    <taglib-uri>http://java.sun.com/jsp/jstl/rrtong</taglib-uri>    <taglib-location>/WEB-INF/jstl/unescape.tld</taglib-location></taglib>    </jsp-config>    <!--定義驗證碼-->    <servlet>      <servlet-name>Kaptcha</servlet-name>      <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class></servlet><servlet-mapping>      <servlet-name>Kaptcha</servlet-name>      <url-pattern>/kaptcha.jpg</url-pattern>    </servlet-mapping>       <!-- 載入dwr -->    <servlet>        <servlet-name>dwr-invoker</servlet-name>        <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>        <init-param>            <!-- dwr測試頁面,上線時設定為false -->            <param-name>debug</param-name>            <param-value>true</param-value>        </init-param>        <!-- dwr攔截 -->        <init-param>            <param-name>org.directwebremoting.extend.Remoter</param-name>            <param-value>com.pinhuba.web.filter.dwrRemoter.DWRRemoter</param-value>        </init-param>        <init-param>            <!-- 防止其他域提交訪問 -->            <param-name>crossDomainSessionSecurity</param-name>            <param-value>false</param-value>        </init-param>        <!-- 壓縮js -->        <init-param>            <param-name>scriptCompressed</param-name>            <param-value>true</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>      <!-- 定義session到期時間 -->    <session-config>          <session-timeout>30</session-timeout>          </session-config>                  <!-- 配置自訂錯誤頁面 -->    <error-page>      <error-code>404</error-code>      <location>/error/404.html</location>        </error-page>      <error-page>      <error-code>500</error-code>      <location>/error/500.html</location>        </error-page>           <!--tomcat叢集配置-->    <display-name>rrtong</display-name>    <distributable/>

    如果通過java讀取param-value,getServletContext().getInitParameter("my_param")方式可以讀取到資料。

    <context-param>        <param-name>my_param</param-name>        <param-value>hello</param-value>    </context-param>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.