在web.xml中添加SpringMvc编写好的过滤器,即可解决乱码
<!--2.配置乱码过滤器-->
<!--所有请求都会被springmvc拦截 -->
<filter>
<filter-name>encoding</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>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意,过滤器的url配置的范围应该为<url-pattern>/*</url-pattern>