编码注意 只有自己能看懂



1.Tomcat启动编码(控制台编码) -Dfile.encoding=UTF8


2.web页面处理编码
 <Connector port="8080"  useBodyEncodingForURI="true"  URIEncoding="UTF-8" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />


request (ISO-8859-1) responset
request.setCharacterEncoding("UTF-8");
String accountID = request.getParameter("account_id");
PrintWriter out = response.getWriter();
response.setContentType("text/plain;charset=UTF-8;pageEncoding=UTF-8");
response.setCharacterEncoding("UTF-8");


3.系统编码 (控制台编码) (如何在DOS窗口中显示UTF-8字符)


4. .java 文件编码 javac -en编码


5.数据库编码
my.ini
my.cnf
SHOW VARIABLES LIKE character_set_%;


6.ecplise | myecplise 文件系统控制台编码


7.数据库连接编码
jdbc:mysql://123.30.133.203:3306/huoying?useUnicode=true&amp;characterEncoding=utf8&mysqlEncoding=utf8




8. 测试System.out.println("################"+System.getProperty("file.encoding"));
测试(UTF-8) System.out.println("chúng tôi vừa gửi mail cho các bạn, các bạn thử xem còn bị loạn mã ko?");






9.有可能出现子集情况若GB2312 是GBK的子集


public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s = encode;
return s;
}
} catch (Exception exception) {
}
encode = "ISO-8859-1";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s1 = encode;
return s1;
}
} catch (Exception exception1) {
}
encode = "UTF-8";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s2 = encode;
return s2;
}
} catch (Exception exception2) {
}
encode = "GBK";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s3 = encode;
return s3;
}
} catch (Exception exception3) {
}
return "";
}


10. linux /etc/sysconfig/i18n

你可能感兴趣的:(编码注意 只有自己能看懂)