web.xml
阿新 • • 發佈:2020-08-27
<?xml version="1.0" encoding="UTF-8"?><!-- 標明使用的XML版本和文件編碼,此項必須位於第一行,之前是空行註釋都不行 --> <!-- web.xml學名為配置部署檔案,是web應用的入口檔案,用於宣告系統的各項配置,此檔案不是必須的,但也只是最簡單的靜態專案才沒有。 xml檔案中大小寫敏感,書寫次序敏感,自上而下載入,所以配置此檔案時要注意標籤的順序和大小寫。 --> <!-- 文件宣告和系統配置宣告,web-app標籤內為具體的部署配置項。 xmlns為xml檔案的名稱空間,xmlns:xsi表示文件遵循的標籤規範,xsi:schemaLocation表示xmlschema地址。 以上三項內容可使用IDE生成或者在web容器配置檔案內找到。 --> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0"> <!-- 應用名稱,提供GUI工具可能會用來標記這個特定的Web應用的一個名稱。 --> <display-name>My Project</display-name> <!-- 歡迎頁面,按順序顯示。 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--前面建立的applicationContext.xml --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>CharacterEncodingFilter</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-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 寫出來ContextLoaderListener --> </web-app>