javaurluriurn

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


Solution

  • 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.