This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes relative and absolute path Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "relative and absolute path" Watch "relative and absolute path" New topic
Author

relative and absolute path

siddharth das
Ranch Hand

Joined: Aug 17, 2007
Posts: 121
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

Joined: Mar 18, 2010
Posts: 457

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.


Regards
KumarRaja

Gaurav Sagar
Ranch Hand

Joined: Sep 08, 2010
Posts: 97

  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.


SCJP 1.6(91%), SCWCD 1.5(100%), SCBCD in progress
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: relative and absolute path
 
Similar Threads
Relative Path - Totally Confusing
Relative Path
absolute or relative
can somebody explain this with eg
How to specify Servlet path in JSP?