• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Paths and requestDispatcher

 
David Swan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me whats the difference between using ../ and just using /
does ../ refer to the parent directory or sumthing???
also therefore i dont know exactly what the difference between request.getDispatcher("../files/index.html") and just request.getDispatcher("/files/index.html")
Does one refer to parent and the other just the relative directory???
Its always the little things that confuse me.....
 
Sathya Sankar
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Your guess is right. ("../files/index.html") refers to the index.htmlin the subdir files that is present in the parent folder of the current jsp/servlet. ("/files/index.html") refers to the index.html in the files dir of the context root folder - the context root folder is the same folder that contains WEB-INF folder.
Hope I've not confused you more :roll:
-GSS
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
Pay attention to the fact that relative path with RequestDispatcher should only be used when you get the RequestDispatcher from an object of type ServletRequest.
In this case, that means that you want a path relative to the path of the current request.
By example, suppose you call the following TestServlet by pointing to the following URL:
http://localhost:8080/tutorial/servlet/TestServlet

By the following code:

you call the following ressource:
http://localhost:8080/tutorial/index.html
Step 1:
http://localhost:8080/tutorial/servlet/TestServlet + ../
-> http://localhost:8080/tutorial/
Step 2:
http://localhost:8080/tutorial/ + index.html
-> http://localhost:8080/tutorial/index.html
If you use the / at the beginning of the path (by using ServletContext.getRequestDispatcher() or ServletRequest.getRequestDispatcher) , the path is interpreted relative to
the current context root (here it means relative to http://localhost:8080/tutorial).
HTH,
Regards,
Cyril.
[ November 21, 2003: Message edited by: cyril vidal ]
 
David Swan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers to both Sathya and Cyril for answering my question. Thanks for explaining that i understand it now
A big Irish "Tanks" to yiz
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic