A few days ago to see a netizen in Ask Urldecoder and urlencoder aspects of the use of the problem, suddenly remembered, I just met these two classes, also feel very close, so you can think of a beginner's mood, so I have this article today.
In fact, the use of these two classes is not complex, urldecoder and urlencoder its role is mainly for ordinary strings and application/x-www-form-rulencodedmime between the string conversion, The average person will think that after a string comparison professional, think there is any advanced knowledge, not actually.
Below, we search for "Network time and Space" in "Baidu", we will see the diagram shown below
It can be seen from this: when we search the key word contains Chinese, these key words will become the "garbled", in fact, this is not garbled, this is called Applicaion/x-www-form-urlencodedmime string.
When a string containing non-Western European characters is included in the URL address, the system will convert these non-Western European special strings, then the encoding process may involve the normal string and this special string related conversion, which is required to use the Urldecoder and Urlencoder class
The Urldecoder class contains a decode (string s,stringcharcter) static method that converts a special string that looks garbled to a normal string
The Urlencoder class contains a encode (string s,stringcharcter) static method that converts a normal string to a application/x-www-form-urlencodedmime string
The following program code
importjava.net.*;
public class Urldecodertest
{
public static void Main (string[] args)
Throws Exception
{
The application/x-www-form-urlencoded string
Convert to normal string
Where the string is copied directly from the window shown.
String KeyWord =urldecoder.decode (
"%cd%f8%c2%e7%ca%b1%bf%d5", "UTF-8");
System.out.println (KeyWord);
Converts a normal string into a
application/x-www-form-urlencoded string
String Urlstr =urlencoder.encode (
"Network Time and Space", "UTF-8");
System.out.println (URLSTR);
}
}
The above program is the conversion between the normal Chinese string and the application/x-www-form-urlencoded mime string.
Run the above program result diagram as follows
About the URL in Java to pass the Chinese parameter, the value is garbled solution