In Java-based programming, often encountered in the Chinese characters and display problems, such as a lot of garbled or question marks.
This problem occurs because the default encoding in Java is Unicode, and the files and db commonly used by the Chinese are based on encodings such as GB2312 or BIG5. I used to make sure that the current page and the target page are consistently encoded to solve most of the problems. But again in the cause of this problem, because the target page could not be encoded (for example, using the Org.glassfish.jersey rest WebService), and then after a lot of data, finally solved, I know there must be a lot of friends will encounter this problem, So special summed up a bit, to come out and let everyone share.
For the WS problem above, you must manually transcode:
1, the output of Chinese in the Web page.
Java is used in network transmission of the encoding is "iso-8859-1", so in the output need to convert, such as:
String str= "Chinese";
Str=new String (str.getbytes ("GB2312"), "8859_1");
However, if you compile the program, the encoding used is "GB2312", and the Chinese platform to run this program, do not appear this problem, it must be stressed.
2. Read Chinese from the parameters
This is exactly the opposite of outputting the output in the Web page:
Str=new String (str.getbytes ("8859_1"), "GB2312");
3, the operation of the Chinese problem in the DB
A simpler approach is to set the area to English (United States) in control face wrench. If there are garbled characters, you can also set the following:
When taking Chinese: str=new String (Str.getbytes ("GB2312"));
Input Chinese to DB: Str=new String (Str.getbytes ("iso-8859-1"));
Java garbled problem Summary