URI vs URL vs URN

Well there are lot of discussion, post, comments and questions over internet to differentiate URI, URL and URN. One answer on SO explain about it, but i am confused in implementation result in my code.

Q : If URI is super set of URL then how come it got this following output:

URI : /XXX/abc.do 

URL : http://examplehost:8080/XXX/abc.do

When i write the below code:

System.out.println(“URI : “+ httpRequestObj.getRequestURI());
System.out.println(“URL : “+ httpRequestObj.getRequestURL());

EDIT : Could you share a detailed answer by keeping JAVA and original concept of URI,URL and URN in scope.

Regards,

Arun Kumar


If URI is super set of URL then how come it got this following output ...

The definitions of URI and URL cannot be used to infer the behaviour of getRequestURI() and getRequestURL() . To understand what the methods return, you need to read the javadocs and the Servlet specification.

The meaning of those methods are what they are because the HttpRequest API has evolved over time, and that evolution has had to maintain backwards compatibility.

getRequestURI() does return a URI, and getRequestURL() does return a URL, but the URI and URL are for different things.


java.net.URI API gives a good explanation:

A URI is a uniform resource identifier while a URL is a uniform resource locator. Hence every URL is a URI, abstractly speaking, but not every URI is a URL. This is because there is another subcategory of URIs, uniform resource names (URNs), which name resources but do not specify how to locate them. The mailto, news, and isbn URIs shown above are examples of URNs.

链接地址: http://www.djcxy.com/p/70454.html

上一篇: URI和URL之间的区别

下一篇: URI与URL与URN