在web.xml文件中增加如下代码:
<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>
注:若工程中没有web.xml文件,则鼠标右击项目名,点击Java EE Tools下的Generate Deployment Descripter Stub即可生成web.xml。