要使用Spring MVC需要在Web项目配置文件中web.xml中配置Spring MVC的前端控制器DispatchServlet
1 <servlet> 2 <servlet-name>SpringMVC</servlet-name> 3 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4 <!-- 默认所对应的配置文件是WEB-INF下的{servlet-name}-servlet.xml,这里可以自定义路径 --> 5 <init-param> 6 <param-name>contextConfigLocation</param-name> 7 <param-value>classpath:/config/spring/springmvc-servlet.xml</param-value> 8 </init-param> 9 <load-on-startup>1</load-on-startup> 10 </servlet> 11 <servlet-mapping> 12 <servlet-name>SpringMVC</servlet-name> 13 <url-pattern>/</url-pattern> 14 </servlet-mapping>