• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

relative and absolute path

 
siddharth das
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a question
In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

what does the absolute path means ..Is it the path from context root to the resource?
And what does the relative path means ..which one the current directory..

Can you please explain by giving an example?

Thanks,
Siddharth
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
siddharth das wrote:Hi ,
I have a question
In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

what does the absolute path means ..Is it the path from context root to the resource?
And what does the relative path means ..which one the current directory..

Can you please explain by giving an example?

Thanks,
Siddharth


May be this will help. I'm sure you will find questions posted on this topic in javaranch.
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  app
       |
       |----JSP
       |       |---Check.jsp
       |       |---Home.jsp
       |
       |----HTML
               |---Contact.html
               |---Downloads.html

Let this be the directory structure of you web application "app" with two subdirectories JSP and HTML containing Check.jsp & Home.jsp and Contact.html & Downloads.html.

The ABSOLUTE PATH of Check.jsp would be "/JSP/Check.jsp"and that of Contact.html is "/HTML/Contact.html". The absolute path always start with a slash "/". This is the path of your resource from the root directory of your web application.

Proceeding now, lets say you are accessing Check.jsp and from there you want to forward to Home.jsp using Request Dispatcher then the relative path would be simply "Home.jsp" or "./Home.jsp"(since, you are already accessing in the JSP directory). If, you want to forward to Downloads.html then the relative path would be "../HTML/Downloads.html".
Here "." means the current directory, and ".." the parent directory.

NOTE: The relative path never starts with a slash "/". It is always relative to the current directory your resource lies(i.e. the one from where you forward, include or redirect).
Hope you get it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic