aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Relative Path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Relative Path" Watch "Relative Path" New topic
Author

Relative Path

Sehrish Hasan
Ranch Hand

Joined: Aug 15, 2005
Posts: 43
When you use relative path like "/hello.jsp". Is it relative to Servlet Context, web app root or server root???

What is a difference between relative path and non-relative path? Also, what is a virtual path???

COuld somebody please explain these concepts?

Thanks,
M Abidi.
Aruneesh Salhotra
Ranch Hand

Joined: May 12, 2004
Posts: 167
When u something like
http://localhost:8080/hello.jsp
It is coming from ROOT application

When u something like
http://localhost:8080/app1/hello.jsp
It is coming from app1 application.

It is relative to the web app you are in. (like in 2nd case, it is app1)
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
There are three types of paths:
1) absolute path: starts with protocol name, then optional port and then server name. "http://myserver.com/myapp/my.jsp" is an absolute path
2) context-relative path. It starts with /. Then follows a path to the resource relative to the application context. "/my.jsp" is a context-relative path.
3) resource-relative path. Starts with the path to the resource relative to the current resource (such as page or servlet or file). "my.jsp" is a resource-relative path. "./my.jsp" also is also a resource-relative path

The difference between relative paths can be cleared by the text, in which they are used.

Virtual path is a path to the resource, created by means of the server. (Typical examples - by using url-pattern).
[ August 15, 2005: Message edited by: Sergey Tyulkin ]
Sehrish Hasan
Ranch Hand

Joined: Aug 15, 2005
Posts: 43
Thanks for replying to my post.

I am still confused. What is the differenc between servlet context root and servlet container root? Do they both refer to web app root??

So basically, Relative Path starting with / is relative to the web app root

Relative path not starting with / is relative to the current resource.

Also, "./foo.html" and "foo.html" has the same effect.

If what I wrote above is true then how do you write a path relative to the ROOT directory of the tomcat???
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
There is special kind of web application - ROOT web application, that can be reached with empty context root. (something like www.mycompany.com - without /myapp/)
Anyway, you cannot reach tomcat's root directory! You can reach only those resources, which are stored in your application's directory. And ROOT application (although its context path is "/") also has its own directory, that can be found under webapps subdirectory in the Tomcat's directory. The directory's name is also "ROOT".
And you can reach any resource from this directory, if your application is deployed in this directory.
Sehrish Hasan
Ranch Hand

Joined: Aug 15, 2005
Posts: 43
Can somebody please explain the difference between servlet context root and servlet container root? Do they both refer to web app root??

Thanks,
M Abidi.
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
We are talking about web applications, right?
So servlet context root is root directory of the current web application.
And for web applications there's no notion of "servlet container root".
But you must remember, that servlet container can have ROOT (or default) web application. It's an ordinal web application, with some different behaviour in distributed environment.
I think, the authors better use "default web application" instead of "ROOT" web application
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relative Path
 
Similar Threads
Including a file in JSP
sendRedirect
Can servlet use the file which is kept outside the classes folder.
servlet initializatoin parameter to get relative path and file name
Servlets and relative file path io