web.xml
<!-- 配置SpringMVC前端控制器 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 自动启动前端控制器 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<!-- / 包括静态和动态请求, /* 匹配动态请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 配置字符集编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
springMVC-servlet.xml ---(web.xml中servlet-name的属性)+ “-servlet”
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 开启springMVC注解驱动 -->
<!-- <mvc:annotation-driven/> -->
<!-- 开启springMVC注解驱动(带类型转换服务) 如果不带类型转换服务加上conversion-service="conversionService(自定义类型转换服务的ID)"会报错 -->
<mvc:annotation-driven conversion-service="conversionService"/>
<!-- 开启注解扫描器 -->
<context:component-scan base-package="com.mitu.controller" />
<!-- 配置页面处理器映射(必配) -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<!-- 配置页面处理器适配器(必配) -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!-- 配置视图解析器(必配) -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<!-- 逻辑视图前缀 -->
<property name="prefix" value="/jsp/" />
<!-- 逻辑视图后缀 -->
<property name="suffix" value=".jsp" />
</bean>
<!-- 配置访问静态资源(必配) -->
<mvc:default-servlet-handler />
<!-- 配置自定义类型转换服务 -->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- 注册自定义类型转换器 -->
<property name="converters">
<list>
<bean class="com.mitu.converter.StringToDateConverter" />
<!-- 添加其它自定义类型转换器 -->
</list>
</property>
</bean>
<!-- 配置请求页面控制器映射 -->
<bean name="/login" class="com.mitu.controller.LoginController" />
</beans>