The Servlet sends the encoding of Chinese data to the client.
(For more information, see your subscription ID: it_pupil)
Get the string, encoded in a specific form into a byte array (such as a UTF-8 ). (You manually convert the byte array)
Tells the browser to decode the display (UTF-8) in the same way ).
If you are using a compaction stream, pay attention to three points:
The character stream is actually a character that you pass to it, and it will still be converted into bytes.
Get the string and tell the server that it is encoded as a byte array (such as a UTF-8) in a specific way at the time of sending ). (Byte arrays are converted internally by the swap Stream)
Tells the browser to decode the display (UTF-8) in the same way ).
As mentioned above, there are three implementation schemes to ensure no garbled code (also a solution to garbled code ):
Solution 1: byte stream:
Solution 2: streaming:
Solution 3: streams:
Solution 3 can simulate the encoding/decoding process as follows (the toHex method outputs the byte array in hexadecimal format ):
Therefore, the key of Solution three is that, at the beginning of the UTF-8 encoding, and finally Decoding with UTF-8, this is the essence.
Although the ISO-8859-1 is a single byte encoding, but, after starting with the UTF-8 encoding, you use the ISO-8859-1 decoding, it will be a byte to unlock, while the UTF-8 represents the Chinese characters, A Chinese Character consists of three bytes. Of course, it will contain garbled characters.
But it doesn't matter if it is garbled. This garbled code is only an intermediate process and does not need to be displayed. Followed by ISO-8859-1 re-encoding, then the encoded bytes are the same as the UTF-8 encoded bytes.
So, finally use the UTF-8 to decode, perfect!
This is the first article on encoding analysis:
Http://mp.weixin.qq.com? _ Biz = MzIyNzUzNjQ3MA ==& tempkey = 37C % 2F % 2BA4Bi9W % 2F7a0wo % %%%%%2bxxzpe3hd % %%2fejgyzg8vxrq % 3D % 3D & # rd
For more information, see related subscription numbers.