The encodeURI function uses the UTF-8 to encode the URL, so if the server is decoding using the other encoding method will be garbled, the default server configuration of the decoding character set is not UTF-8, so most of the time the address bar to submit Chinese query parameters will produce garbled In this case, you can use encodeURI two times in a row to encode non-English characters on the client (primarily the browser) and then use Java.net.URLDecoder (String. ") on the server side. UTF-8 ") to get the correct Chinese.
Principle:
If only one encodeURI, get the UTF-8 form of the URL, the server side through Request.getparameter () decoding query parameters (usually iso-8859-1) will get garbled.
If two times encodeURI, the first encoding is the UTF-8 form of the URL, the second encoding is still the UTF-8 form of the URL, but the effect is equivalent to the first UTF-8 encoding (now all converted to ASCII characters), Once again, iso-8859-1 encoding, because the English characters say UTF-8 encoding and ISO-8859-1 encoding the same effect. On the server side, the first decoding via Request.getparameter () first (possibly the character set of the gb2312,gbk,utf-8,iso-8859-1, which has no effect on the result) obtains the ASCII character, Then use UTF-8 for a second decoding, usually using the Java.net.URLDecoder ("", "UTF-8") method.
The process of encoding two times for two times is:
UTF-8 encoded->UTF-8 (iso-8859-1) encoding->iso-8859-1 decoding->utf-8 decoding, encoding and decoding process is symmetric, so there is no garbled.
URL two-time encoding