记录一个肯定能解决问题的办法,配置spring的内置过滤器CharacterEncodingFilter(字符编码过滤器),用来强制转换请求或响应的编码格式。
配置方法:在配置文件web.xml中加入以下代码:
<filter>
<filter-name>characterEncoding</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>characterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>