Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

relative/absolute paths

 
Amit Ghag
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We say some methods do not accept relative paths. Does that mean these methods do not accept page-relative/file-relative paths but accept context-relative paths ?
Please elaborate the difference between relative and absolute paths...
 
peter parker
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
An absolute path contains the full URL of the item being referenced. A relative path contains directions to the item relative to the HTML page.
For example:
Let's say that we have a directory structure that looks like the following
+ development
- images
- jsp
Now let's say that index.jsp is in the development folder. Index.jsp is simply a redirect page to a file called home.jsp in the jsp folder.
This redirect can be accomplished in two ways. First by using a relative path, meaning that, given the page/file current location use
../ or / (move up directory or move down directory) to access the contents of another directory. In this case, since we're trying to call home.jsp by using a relative path from index.jsp in the development folder we would say:
redirect(/jsp/home.jsp);
The other means is the absolute path, which is simply the complete URL location need to locate the page/file. In this case we would say:
redirect(http://myServer.com/development/jsp/home.jsp);
hope this helps.
-PP
 
Amit Ghag
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx PP,
Just one more question. How do we specify the path of the file which is in the parent directory of the development folder ( in ur example ). Do we specify it like this--
redirect("../testing/test.jsp");
where 'testing' is in the same folder as 'development' and 'test.jsp' is a file under 'testing'.
 
Amit Ghag
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any tips to remember which methods of the Servlet API accept only relative paths or only absolute paths as parameters ?
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going through APIs .... till now I think only ServletRequest.getRequestDispathcher() takes relative path.
Other methods take absolute path i.e. paths starting with "/" which is taken as relative to context of the web-app.
CMIW (Correct Me if I am Wrong)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic