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?