From: http://www.cnblogs.com/kadinzhu/archive/2011/05/02/2034394.html
When writing a JSP page today, a Chinese string is passed to another page in the form of URL parameters. However, garbled characters are found in the Chinese characters on the other page when parsing this parameter. Suppose that I have assigned the Chinese string in the request to the STR string, how can I get the correct string value? I checked a lot of information and finally found a better explanation:
All character set definitions except the UTF-16 are repeated. For example, if the Chinese character "I" is assumed to have a value of 22530 (just assume that I did not check the specific number)
and the value of "Japanese" may also be 22530 (also assumed) or the Korean "bytes" cannot be transmitted in high bytes over the network, because only the unsigned char is recognized at the bottom of the network, which is equivalent to the byte in Java, therefore, the int 22530 must be converted to a byte array. byte [0] = (22530> 8) & 0xff; byte [1] = 22530 & 0xff;
I did not calculate the actual number. If byte [125,231] is a byte sent to the server, does it indicate "I", "Japanese", or other Chinese characters?
generally, the character set is notified in the communication protocol. For example, when HTTP requests are sent to the server, contenttype = "xxxxxxxxxx"; charset = "gkb ";
at this time, the server will know that the [125,231] received is gkb "me" instead of other text. The above is a standard communication process. However, if some Program Members do not notify the server-side character set when submitting a request, the server cannot do so. You have to guess the default one based on the most common character set. This is not bad. the most terrible thing is that when the programmer level and knowledge of the write server are poor, it will be terrible. Just like a programmer who writes older versions of Tomcat, he was born in the West and thought that everyone in the world is using 26 letters and some symbols, so no matter what the client submits, he is decoding by ISO-8859-1, the results can be imagined.
For example, we use GBK encoding to submit a string to the server, in Tomcat, It decodes this string with a ISO8859-1, and sends it to the destination Page, this produces an error. So we can use new string (Str. getbyts ("ISO8859-1"), "GBK"), first from the server parameters according to the ISO8859-1 encoding, and then the encoding results with GBK decoding, forming a string, you can get the correct value.
No way, who let us use GBK people will not write tomcat, so first let the bad programmer error generated string with the ISO-8859-1 back
[125,231], and then use gkb to generate a string.