web.xml配置

名稱:web.xml
目錄:/webapp/WEB-INF/web.xml
內容:過濾器、Servlet


<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  
  <!-- 定位applicatioinContext.xml路徑 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
 
  <filter>
      <filter-name>springEncoding</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>
      <init-param>
          <param-name>forceEncoding</param-name>
          <param-value>true</param-value>
      </init-param>
  </filter>
  
  <filter>
    <filter-name>openSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
  </filter>
  
  <filter>
      <filter-name>sessionFilter</filter-name>
      <filter-class>com.troyforever.example.filter.SessionFilter</filter-class>
  </filter>
  
  <filter-mapping>
      <filter-name>springEncoding</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <filter-mapping>
    <filter-name>openSessionInView</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
    <filter-mapping>
      <filter-name>sessionFilter</filter-name>
      <url-pattern>/admin/*</url-pattern>
  </filter-mapping>  

  <!-- 加載applicationContext.xml配置文件 -->
    <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

   <servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  
  <servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  

</web-app>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 大家好,我是IT修真院深圳分院第1期學員,一枚正直純潔善良的web程序員。今天給大家分享一下,修真院官網JAVA(...
    老菜菜閱讀 751評論 0 1
  • 1. web.xml配置詳解 <web-app> <!--指定WEB應用的名字--> <display-n...
    zhglance閱讀 808評論 0 1
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,869評論 18 139
  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,941評論 6 342
  • 有些事情,只能自己一個人過!不是每一個人給你的傷害都是應該的!也不是每一個看起來很好的意見都應該被采取,有些人,有...
    被關注的舊時光閱讀 181評論 0 0