This is from API doc about ServletContext.getResource(String)
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.
What I don't understand here is that it is relative to the current context root and at the same time the resource can be local, remote, in database or in a .war. I thought that relative to context path means that it starts with "/" and that means that I have access starting from the root of my application which would exclude remote and other resources ....
Could someone please explain it ?
Adrian [ April 08, 2008: Message edited by: Bear Bibeault ]
You can't fet a java.io.File reference to a file within a WAR or JAR, but you CAN get a URL pointing to it.
If the web application loads the resource from a remote resource, then the URL will refer to this remote resource. I'm not sure how you get a URL to a database resource, but I am keen to be enlightened.
Yes - I agree with what you say, but what I mean is, according to the documentation and spec, the URL has to start with "/". How can an URL refer to a remote resource when it starts with "/" ? That's what I don't understand ....