Why does the Chinese in the URL need to be encode two times?

Source: Internet
Author: User

It is often necessary to pass in Chinese when the parameter is passed in the URL, this time it is necessary to encode the Chinese parameters, that is urlencode. But it is often encode two times, not once, why?

The first thing to know is that Tomcat will automatically decode it once;

In this case, if only encode once to pass the past, there will be two kinds of situations:

1.Tomcat decode character set is consistent with your encode character set, normal display Chinese;

2.decode and encode character set inconsistent, garbled;

Now suppose encode two times, then:

Tomcat decodes once, encode the string out once;

The programmer manually decode a character set, which can be successfully decoded as long as the given character set is consistent with the encoding.

Summary: Encode two times is in order to get control of the decoding character set, the decoding character set set from the Tomcat set the value of free, decentralized to Java code, let the programmer control.

Only to know here temporarily, follow up again.

Attached: Figuring out the codec http://www.xuebuyuan.com/1287083.html in Tomcat

Why does the Chinese in the URL need to be encode two times?

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.