Get JVM Default Character set: System.getproperty ("file.encoding")
public class Test {public
static void Main (string[] args) {
System.out.println (System.getproperty (" File.encoding "));
}
Get different lengths of Chinese characters
public class Test {public
static void Main (string[] args) {
System.out.println ("Test". GetBytes (Charset.forname (" UTF-8). length);//Result: 3 System.out.println ("
test". GetBytes (Charset.forname ("GBK")). length);//Result: 2
}
}
Through the above tests to draw a general result: XP system installation Tomcat get the default character set for Gbk,linux depending on the language different from the general system porting from under Windows easily garbled (test method can create a new charset.jsp, add the following content).
<%=system.getproperty ("file.encoding")%>
There are two ways to unify the JVM character set: One is to use a uniform character set, such as GetBytes ("GBK"), and so on, when the character set is required, and the second, to specify the java_opts parameter during tomcat startup-dfile.encoding =utf-8 "
java_opts= "$JAVA _opts-dfile.encoding=utf-8"