先有個一個web項目
該web.xml配置是基於spring配置的
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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"> <welcome-file-list> <!--運行服務器后,設置項目跳轉的起始頁面--> <welcome-file>login</welcome-file> </welcome-file-list> <display-name>Develop Example</display-name> <!--項目名--> <description>JSP 2.0 Tech Book's Examples</description> <!--項目描述--> <icon> <small-icon>/images/1.gif</small-icon> <large-icon>/images/2.gif</large-icon> </icon> <!--元素含有一對參數名和參數值,用作應用的servlet上下文初始化參數。參數名在整個Web應用中必須是惟一的。--> <context-param> <param-name>contextConfigLocation</param-name> <!--參數名--> <param-value>classpath*:spring-mybatis.xml,classpath*:spring-context-shiro.xml</param-value> <!--參數值--> </context-param> <!--filter元素用於指定Web容器中的過濾器。在請求和響應對象被servlet處理之前或之后,可以使用過濾器對這兩個對象進行操作。--> <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> <!--值 為utf-8--> </init-param> </filter> <!--filter-mapping元素用來聲明Web應用中的過濾器映射。過濾器可被映射到一個servlet或一個URL模式。將過濾器映射到一個 servlet中會造成 過濾器作用於servlet上。將過濾器映射到一個URL模式中則可以將過濾器應用於任何資源,只要該資源的URL與URL模式匹配。--> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> <!--映射到url模式,並與/*匹配--> </filter-mapping> <!----> <!--<servlet>--> <!--<servlet-name>TestController</servlet-name>--> <!--<servlet-class>com.ztzg.controller.TestController</servlet-class>--> <!--</servlet>--> <!-- Spring監聽器 --> <!--ContextLoaderListener會讀取這些XML文件並產生 WebApplicationContext對象,然后將這個對象放置在ServletContext的屬性 里,這樣我們只要可以得到Servlet就可 以得到WebApplicationContext對象,並利用這個對象訪問spring 容器管理的bean。--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 防止Spring內存溢出監聽器 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- Spring MVC servlet --> <servlet> <servlet-name>spring-mvc</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> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> </web-app>
對上面的配置一知半解,以后深入再做說明修改