A detailed distinction between URLs and URIs (with instances) __java

Source: Internet
Author: User
Tags rfc url example

1 Description:

This time to write Android when the URL and URI, a bit unclear, so did a systematic study. Here will be their own learning notes pasted out, I hope to help.

1 The Java class Library has two corresponding classes Java.net.URL and Java.net.URI, the official definitions are as follows:

(URL) A uniform Resource Locator thatidentifies The location of an Internet Resource as specified by RFC 1738. ( Uniform Resource Locator 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. (a Uniform Resource Identifier is used to indicate an abstract or physical resource)

2 in other words, the URI is an abstract, high-level concept to define the Uniform resource identity, and the URL is the way to identify the specific resource. A URL is a URI.

3 Url,uri specific definition (from the official Android document)


The format of a URL generally consists of the following three parts:

The first part is the agreement (or service mode);

The second part is the host IP address (sometimes including the port number) that contains the resource;

The third part is the specific address of the host resource.

A URI generally consists of three parts:

The naming mechanism for accessing resources.

Host name where the resource is stored.

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 grammatical rules of the URI. The URL class not only conforms to semantics, but also contains information to locate the resource, so it cannot be relative, and schema (protocol) must be specified.

2 Example:

1 when you usually use pictures. In the end is Imgurl good, or Imguri good. Obviously, if Imgurl is definitely fine, because even if it's actually a URL, it's also a URI. Then use Imguri.

Is there a problem? At this point depends on its possible value, if it is an absolute path, can be positioned, then use Imguri is no problem, and if it is relative path, it is better not to use Imguri. In short, the use of Imgurl is certainly no problem, and the use of Imguri depends on the actual situation.

2) Stringhttpservletrequest.getrequesturi (); and Stringbufferhttpservletrequest.getrequesturl (); What is the difference between the returned contents? Why is this.

As you can see from HttpServletRequest's Javadoc, Getrequesturi returns a string, "the part of this request's URL from Theprotocol name up to the Q Uery string in the "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 it's Getrequesturi instead of 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 the file is represented by a URL, the server is represented by the filename, followed by the host IP address, the file's access path (that is, the directory), and the file name. Sometimes the directory and file names can be omitted, but the "/" symbol cannot be omitted.

Example (3.1): File://ftp.linkwan.com/pub/files/foobar.txt

Represents a file in the pub/files/directory on the host ftp.linkwan.com, and the file name 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 resources for hypertext information Services.

Its computer domain name is homepage.yesky.com. The super text file (the file type. shtml) is 2603675.shtml under directory/175. This is a computer in Tenkine.

4 a Uniform Resource Locator (URL) is the address of an Internet file on the Web. Like a street in the city geographical address. URLs use numbers and letters in a certain order to determine an address. For example, if a person's address is:

510665 Guangzhou Tianhe Branch Rhyme Road 18th beam Big Head

You will think, Liang Big Head is a name, he lives in Guangzhou Tianhe Branch Rhyme Road 18th, zip code is 510665.


3: summary

Web site for reference:

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

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.