在使用spring中,能夠在web.xml中添加CharacterEncodingFilter過濾器解決亂碼問題,代碼以下:java
<!-- post提交解決亂碼過濾器 --> <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>
也遇到過添加了這個過濾器以後,表單提交過來的中文字符串在Controller中打印出來仍然是亂碼,多是Controller的編碼問題,建議經過修改整個workspace的編碼爲UTF-8:web
2. 待補充...
spring