1、Spring MVC应用一般包括以下步骤:
1. 配置web.xml,指定业务层对应的Spring配置文件,定义DispatcherServlet;
2. 编写处理请求的控制器;
3. 编写视图对象;
4. 配置Springl MVC的配置文件,使控制器、视图解析器生效。
2、配置DispatcherServlet,截获特定的URL请求web配置示例:
<context-param>
<param-value>contextConfigLocation</param-value>
<param-value>classpath:/conf/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listen-class>
</listener>
<!--声明DispatcherServlet-->
<servlet>
<servlet-name>servletName</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--名为DispatcherServlet匹配的URL模式-->
<servlet-mapping>
<servlet-name>servletName</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
3、简单web层Spring配置示例:
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/webApplicationContext.xml
</param-value>
</init-param>