spring Web MVC框架提供了org.springframework.web.filter.CharacterEncodingFilter用於解決POST方式形成的中文亂碼問題,只須要在web.xml中配置一個filterweb
<filter> <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>