users@glassfish.java.net

Re: Read file from docroot

From: <glassfish_at_javadesktop.org>
Date: Tue, 06 Nov 2007 11:57:28 PST

Hi Kedar,

the purpose of ServletContext.getResource() *is* to provide access to resources stored in the webapp's context root. "context root" and "docroot" are used synonymously.

On the other hand, a webapp's classloader is initialized only with resources from the webapp's WEB-INF/classes and the JAR files under its WEB-INF/lib directory.

Therefore, if your webapp has a resource "someresource.txt" at the top-level of its WAR, you can access it only using

ServletContext.getResource("/someresource.txt")

and not using the webapp's classloader.

Jan
[Message sent by forum member 'jluehe' (jluehe)]

http://forums.java.net/jive/thread.jspa?messageID=244142