1.導入SpringMVC的jar包
2.配置web.xml(配置SpringMVC的前端控制器DispatchServlet及定義SpringMVC配置文件的位置)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVC_cuowuxx</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置SpringMVC -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<!-- 引用SPringMVC架包的DIspatchServlet配置 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 進行初始化,配置SPringMVC環境位置,爲classpath目錄下名字爲springMVC.xml的文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
</servlet>
<!-- 引用映射上面SpringMVC配置,作用在每個以.action結尾請求路徑(這裏的servlet-name的名字一定要與上面的servlet-name名字相同才能調用映射上面的SPringMVC配置) -->
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!-- 配置調用springMVC過濾器,來解決亂碼的問題 -->
<filter>
<filter-name>Filter</filter-name>
<!-- 引用SPringMVC架包的CharacterEncodingFilter過濾器 -->
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!-- 在進行初始化時,設置其編碼爲UTF-8 -->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<!-- 引用映射上面配置的過濾器,並且作用在每個文件和請求上 -->
<filter-mapping>
<filter-name>Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>