Java Code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://dingbuoyi.javaeye.com/blog/836621# ">
-
- String urlstring ="Http: // 192.168.21.77: 8080/SWP/mainpage? AA = 11 & BB % 3d22";
-
- Uri uri = URI. Create (urlstring );
-
- System. Out. println (URI. getpath ());
-
- System. Out. println (URI. getquery ());// Decoding
- URL url2 =NewURL (urlstring );
-
- System. Out. println (url2.getquery ());// Do not decode
String urlstring = "http: // 192.168.21.77: 8080/SWP/mainpage? AA = 11 & BB % 3d22 "; Uri uri = Uri. create (urlstring); system. out. println (URI. getpath (); system. out. println (URI. getquery (); // decoded URL url2 = new URL (urlstring); system. out. println (url2.getquery (); // do not decode
Uri Decoding
REFERENCE Note: The URI class can escape the fields in certain situations. We recommend that you use URI to manage URL encoding and decoding, and use touri () and Uri. tourl () to convert the two classes.
You can also use the urlencoder and urldecoder classes, but they are only applicable to HTML encoding, which is different from the encoding mechanism defined in rfc2396.
A reference URI is a pure syntactic structure used to specify different parts of a string that identifies a web resource. A URL is a special case of Uri. It contains sufficient information to locate web resources. Other Uris, such:
Mailto: cay@horstman.com
It does not belong to the positioning operator because no resource can be located based on the identifier. A URI like this is called urn (Uniform Resource Name ).
In the Java class library, the URI class does not contain any methods to access resources. Its only function is to parse. On the contrary, the URL class can open a stream that reaches the resource. Therefore, the URL class can only act on the modes that Java Class Libraries know how to handle, such as http:, https:, ftp:, local file system (File :), and JAR file (jar :).
One of the functions of the URI class is to parse the identifiers and break them into different components. You can read them using the following methods:
Getschema
Gethost
Getport
Getpath
Getquery
Another function of the URI class is to process absolute and relative identifiers. If the following absolute URI exists:
Http://docs.mycompany.com/api/java/net/serversocket.html
And a relative URI as follows:
../Java/NET/socket.html # socket ()
Then you can combine them into an absolute URI:
Http://docs.mycompany.com/api/java/net/socket.html#Socket ()
This process is called relative URL conversion.
The opposite process is relative. For example, suppose you have a basic URI:
Http://docs.mycompany/api
And another URI:
Http://docs.mycompany/api/java/lang/String.html
Then the relative URI is:
Java/lang/string.html