• 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

J2EE - Relative Path Vs Absolute Path

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Path starting with / -> Absolute path where / represents the document root of your application.

2. Path starting with ../ -> Relative path, i.e. relative to the current request.

Ques 1. W.r.t 1., will '/' always refer to the document root of our web application? Will our-web-application always be the document root?

Ques 2. w.r.t 1. Consider our-web-application is the document root. If we want to access a html file, then by /login.html, we expect login.html to be present under <our-web-application> (i.e / represents <doc root> BUT when we say /servlet/LoginServlet then we expect LoginServlet to be present under /Web-INF/classes/servlet. Why in this case the <doc root> is changed (surely it is not our-web-application as / represents classes)? Moreover what is / represents in this case ?

Ques 3:
By the statement
req.getRequestDispatcher("../login.html");

what is the current directory so that we can know login.html should be one level up?
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. Path starting with / -> Absolute path where / represents the document root of your application.


Firstly, Path starting with '/' is not absolute path, its relative path. Absolute path include the server name/ip and port etc like http://www.me.com:8080/MyApp.
Secondly, yes '/' represents the document root of you web application.


2. Path starting with ../ -> Relative path, i.e. relative to the current request.


Yes, this is also relative path, '..' denotes one directory up to the current directory


Ques 1. W.r.t 1., will '/' always refer to the document root of our web application? Will our-web-application always be the document root?


Yes '/' will always refer to document root i guess, please correct me if i am wrong


when we say /servlet/LoginServlet then we expect LoginServlet to be present under /Web-INF/classes/servlet.


No, it is not required to place it under /WEB-INF/classes/servlet, you can place it under any package in classes folder.


Why in this case the <doc root> is changed (surely it is not our-web-application as / represents classes)? Moreover what is / represents in this case ?


Servlet's case is somewhat different, you need to specify a URL Mapping for a servlet to access it, and also provide the fully qualified class name to access it, it doesn't require you to put servlet in any specific package. Document root is still the same '/'


By the statement
req.getRequestDispatcher("../login.html");
what is the current directory so that we can know login.html should be one level up?


if you request came as http://someserver:8080/YouApp/admin/pages/index.jsp then it will find login.html in admin directory i.e. one directory up to the current directory of requested page.
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice Explanation Ali
 
reply
    Bookmark Topic Watch Topic
  • New Topic