1. Generally, the Chinese characters in the directory in the url are encoded according to UTF-8, And the UTF-8 encoding is % E4 % B8 % AD. 2. the get method parameters are encoded according to the computer's system language, while the Chinese language is GBK. the GBK encoding in the get method is % D6 % D0, the encoding is % 92% 863 .... syntaxHigh
1. In general, the Chinese characters in the directory in the url are encoded according to UTF-8, And the UTF-8 encoding in "medium" is "% E4 % B8 % AD ".
2. the get method parameters are encoded according to the computer's system language. The Chinese language is GBK, And the GBK of "medium" is encoded as "% D6 % D0"; the Japanese environment is encoded as "shift-jis ", "medium" is encoded as "% 92% 86"
3. Parameters in the post mode will be placed in the http body and encoded according to the content-type in the jsp page.
For a backend decoding:
1. If the matching path in the background contains Chinese characters, decode the Chinese character "medium" in the path in the correct format. The solution can also be:
Add URIEncoding = "UTF-8" to the Connector node of tomcat server. xml to match the Chinese path.
Generally, the path does not contain Chinese characters. In addition, adding URIEncoding = "UTF-8" to tomcat will affect all projects. Therefore, this method is generally not used (I checked it based on my interest ).
2. decode the get parameter correctly.
In tomcat does not add URIEncoding = "UTF-8", tomcat by default according to the iso-8859-1 decoding, so to get the correct Chinese parameters, according to the following method, first decoding and then according to the correct encoding:
System. out. println (new String (request. getParameter ("username"). getBytes ("iso-8859-1"), "parameter encoding "));
Parameter encoding is the encoding of your computer system environment.
If URIEncoding = "UTF-8" is added, theoretically the parameters are decoded according to UTF-8. the GBK-encoded D6D0 does not match the "medium" character in UTF-8, and other characters may appear, therefore, the binary value corresponding to the parameter is changed. Therefore, no matter how the encoding and decoding are performed, the following error occurs:
System. out. println (new String (request. getParameter ("username"). getBytes ("UTF-8"), "parameter encoding "));
System. out. println (new String (request. getParameter ("username"). getBytes ("iso-8859-1"), "parameter encoding "));
It hasn't been solved yet. Please help me.
During the experiment, the Chinese characters in the path and the Chinese characters in the parameters adopt different encodings. We can use javascript to encode the parameters, because encodeURI () the method will encode the parameters according to UTF-8, so ajax can be used for implementation (this is only a solution. If you are interested, try it ).
[Javascript] view plaincopy