解決亂碼問題
1. 將get請求改爲post請求
2. String a=new String(b.getBytes(“iso-8859-1”), “UTF-8”):String(b.getBytes(“iso- 8859-1”), “UTF-8”):將b按 iso-8859-1進行解碼 然後再按UTF-8進行編碼。
3. 在tomcat中配置字符集,eg:配置文件路徑:/{project_tomcat_home}/conf/server.xml
修改內容:在http協議監聽配置上加上URIEncoding=”UTF-8”
eq:<Connector port="9000"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
但是,若在tomcat中已配置字符集,又在代碼中設置String a=String(b.getBytes(“iso-8859-1”), “UTF-8”),同樣會產生亂碼。
此處未寫完…
代碼:
String a = "中間";
String b = new String(a.getBytes("iso-8859-1"), "UTF-8");
String aa = new String(a.getBytes("utf-8"), "iso-8859-1");
String bb = new String(aa.getBytes("iso-8859-1"), "UTF-8");
System.out.println(b);
System.out.println(bb);
輸出內容:
?? ——>產生亂碼
中間 ——>正常