1、跟踪Spring MVC的请求
2、搭建Spring MVC
Spring MVC的核心是DispatcherServlet,充当Spring MVC的前端控制器。
在web.xml中
<servlet>
<servlet-name>example</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
创建example-servlet.xml文件,DispacherServlet将用它来创建应用上下文。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 处理静态资源请求-->
<mvc:resources mapping="/resources/**" location="/resources/*"/>
</beans>
2、编写基本的控制器
2.1、配置注解驱动
<mvc:annotation-driven />
2.2、自动扫描装配
<context:component-scan base-package="com.test.app.mvc" />
2.3解析视图
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>