Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top