• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

relative and absolute path

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 97
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic