In web development, Garbled text is a very common problem. We can solve the Garbled text problem well only by understanding why Garbled text occurs.
1. Why is garbled?
Because Chinese characters cannot appear in the address bar, URL encoding is required when we send Chinese parameters. Because we can use various rules to encode them, when the server receives a message, garbled characters may occur if the rules used by the server are different. For example, in Tomcat, the default decoding is "is0-8859-1", because "iso-8859-1" does not support Chinese, so in the URL encoding, It is not "iso-8859-1", so it will be garbled.
Based on the above reasons, we can think of the following two methods to solve the garbled problem:
1. Modify the default decoding method of Tomcat. (check the network by using the uriencode in server. XML)
2. After receiving the parameter, the server splits it into byte arrays and decodes the new string (parame. getbytes ("iso-8859-1"), "UTF-8 ");