URL two-time encoding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.