可以確定的是ssh裡,在action操作的字符串都是gbk,java文件是utf-8,過濾器也試過了,還是gbk.
用new String(str.getBytes(), "utf-8")這句返回的字符串也是亂碼
1 使用Spring自帶的過濾器
<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>
2 將頁面編碼設置
<@ page language=”java” pageEcoding=”utf-8” />
3 Tomcate配置編碼,server.xml中修改:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
參考:http://blog.csdn.net/steven_oyj/article/details/4757828