This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
Joined: Jun 07, 2007
Thanks for your reply !
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 ....