• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getResource in ServletContext

 
Anay Rai
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Julian Kennedy
Ranch Hand
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic