An understanding of URL Encoding

Source: Internet
Author: User

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 ");

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.