aspose file tools*
The moose likes Servlets and the fly likes getResource in ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getResource in ServletContext" Watch "getResource in ServletContext" New topic
Author

getResource in ServletContext

Anay Rai
Greenhorn

Joined: Sep 07, 2004
Posts: 3
the API doc for getResource method in ServletContext interface says that

This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.

My question is, How to access resources on remote machine?
do we have to give IP address of remote machine or what?
the path should begin with '/', which is path in current context...so how do we give path for remote machine.
Which containers allow this?

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"v an"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
OK, so the API doc says:

public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException

Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.

So, the "path" parameter clearly has to point to a location (resource) under the context root. However, if the resource that is pointed to is a symbolic link in UNIX or a shortcut in Windows (?) then it can ultimately point anywhere, not necessarily just on the same machine. I assume this is what it means but I'll admit I'm not on firm ground here. Maybe you could try it out and let us know.

It doesn't sound like this is an optional feature so I'd expect all servlet containers to do it.

Jules
 
jQuery in Action, 2nd edition
 
subject: getResource in ServletContext