1 Description:
This period of time to write Android use URL and URI, a bit unclear, so did a systematic study. Here will be your own study notes pasted out, I hope to be helpful to everyone.
1) Java class Library has two corresponding classes Java.net.URL and Java.net.URI, the official definition is as follows:
(URL) A Uniform Resource Locator thatidentifies The location of the Internet Resource as specified by RFC 1738. ( Uniform Resource Locator is used to indicate the location of network resources.
(URI, Uniform Resource Identifier) A Uniform Resource Identifier that identifies an abstract or physical Resource, as specified by RFC 2396. ( Uniform Resource Identifiers are used to indicate an abstract or physical resource)
2) This means that the URI defines the uniform resource identity in an abstract, high-level concept, and the URL is the exact way the resource is identified. A URL is a URI.
3) Url,uri specific definition method (from Android Official document)
The format of the URL is generally composed of the following three parts:
The first part is the agreement (or service mode);
The second part is the host IP address (and sometimes the port number) where the resource is stored;
The third part is the specific address of the host resource.
URIs are generally made up of three parts:
The naming mechanism for accessing resources.
Host name of the storage resource.
The name of the resource itself, represented by the path.
4) In the Java URI, a URI instance can represent absolute or relative, as long as it conforms to the syntax rules of the URI. The URL class not only conforms to semantics, but also contains information that locates the resource, so it cannot be relative, and schema (protocol) must be specified.
2 Examples:
1) People usually use the picture when. is Imgurl good, or Imguri good? Obviously, if Imgurl is definitely not a problem, because even if it is actually a URL, it is also a URI. So use Imguri.
Do you have any questions? At this point to see its possible value, if it is an absolute path, can be positioned, then use Imguri is not a problem, and if it is a relative path, that still do not use Imguri good. In short, with Imgurl is sure no problem, and the use of Imguri depends on the actual situation.
2) Stringhttpservletrequest.getrequesturi (); and Stringbufferhttpservletrequest.getrequesturl (); What is the difference in what is returned? Why is that so?
As can be seen from the Javadoc of HttpServletRequest, Getrequesturi returns a string, "the part of this request's URL from Theprotocol name up to the Q Uery string in the first line of the HTTP request ", such as" Post/some/path.html?a=b http/1.1 ", the value returned is"/some/path.html ". Now you can see why Getrequesturi is not getrequesturl, because the relative path is returned here. And Getrequesturl returns a StringBuffer, "The returned URL contains a protocol, server name, port number, andserver path, but it doe s not include query string parameters. ", complete request resource path, excluding querystring.
3) URL Example
URL of the file: When a file is represented by a URL, the server is represented by a filename, followed by information such as the host IP address, the file's access path (that is, the directory), and the filenames. Directories and file names can sometimes be omitted, but the "/" symbol cannot be omitted.
Example (3.1): File://ftp.linkwan.com/pub/files/foobar.txt
Represents a file under the Pub/files/directory on the host ftp.linkwan.com, and the filename is foobar.txt.
Example (3.2): File://ftp.linkwan.com/pub
Represents the directory/pub on the host ftp.linkwan.com.
Example (3.3): file://ftp.linkwan.com/
Represents the root directory on the host ftp.linkwan.com.
Example (3.4): http://homepage.yesky.com/175/2603675.shtml
HTTP URL: Use Hypertext Transfer Protocol HTTP to provide hypertext Information service resources.
Its computer domain name is homepage.yesky.com. The super text file (the file type is. shtml) is 2603675.shtml under catalog/175. This is a computer of Yesky.
4) the Uniform Resource Locator (URL) refers to the Internet file address on the Internet. Like a street in the city geographic address. URLs use numbers and letters arranged in a certain order to determine an address. For example, if a person's address is:
510665 Guangzhou Tianhe Branch Yun Road No. 18th Beam Big Head
You will think, Liang Big Head is a name, he lives in Guangzhou Tianhe Branch Yun Road 18th, zip code is 510665.
3: summary
References to the website:
Http://www.cnblogs.com/gaojing/archive/2012/02/04/2413626.html
http://blog.csdn.net/niuox/article/details/7312843
Http://cs.szpt.edu.cn/android/reference/java/net/URI.html (official)
Http://cs.szpt.edu.cn/android/reference/java/net/URL.html (official)
Http://www.cnblogs.com/devinzhang/archive/2012/01/08/2316443.html
The difference between URI and URL (go)