ssm專案學習3-ssm整合的關鍵配置檔案(web.xml等)
1.在web.xml中編寫ssm整合的關鍵配置檔案(包括:web.xml、spring、 springwebmvc的等)
首先在web.xml中:
1. 加入啟動spring的容器的配置檔案: #contextloaderlisterner
在<param-value>classpath:applicationContext.xml</param-value> 指定載入某一處的路徑下的spring的配置檔案
注: applictionContext.xml檔案中:<!-- spring 的配置檔案,這裡主要是配置和業務邏輯有關的-->
2.#springDispatcherServlet
<!-- spring mvc的前端控制器 攔截所有的請求 -->
注:<!--兩種方式:
1.可以在<param-value>location</param-value> 中指定classpath的<param-value>classpath:applicationContext.xml</param-value> 指定載入某一處的路徑下的spring的配置檔案
2.可以直接用location 但是配置檔案必須放在 命名必須是springDispatcherServlet-servlet.xml
此檔案放在webapps下的web-inf包下
-->
3. 字元編碼過濾器配置<fiter>
把字元編碼拿來變成請求
(ps:eclipse快捷鍵小技巧:開啟型別:Ctrl+Shift+T)
需要CharacterEncodingFilter、HiddenHttpMethodFilter
CharacterEncodingFilter:
1.首先要將encoding設定為utf-8
2.將CharacterEncodingFilter中所提供的兩個boolean型別的變數設定為true
分別為:forceRequestEncoding、forceResponseEncoding
HiddenHttpMethodFilter:
這個是rest風格的uri:就是可以將頁面的post請求轉化為delete和put請求
其次是在disapplicationservlet-servlet.xml檔案中的一些配置
disapplicationservlet-servlet的檔案中:是關於一些springmvc的配置檔案 包括了網頁的跳轉邏輯和控制以及配置網站有關的一些配置
1.<context:component-scan>掃描包 可以在標籤中指定只掃描註解為controller(控制器)的
2.<bean> 配置檢視解析器:方便頁面的返回
3.這兩個為springmvc的標配:
首先是:<mvc:default-servlet-handler> :將springmvc的不能出處理的請求交給tomcat處理
其次是:<mvc:annotation-driven>:加上它能讓springmvc支援更多的功能。