List Info

Thread: Re: Read file from docroot




Re: Read file from docroot
user name
2007-11-06 13:57:28
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


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeglassfish.dev.java.net
For additional commands, e-mail: users-helpglassfish.dev.java.net


Re: Read file from docroot
user name
2007-11-06 14:15:59
> 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.

I'll take "conflating vocabulary for $100 Alex!".

When *I* see "docroot", I'm thinking the docroot
of the virtual host, which is not necessarily the same as
the context root of the application.

Now, if you want to get access to a File that is deployed in
a WAR, that's a different problem.

This can easily be done.

What you are looking for is:

String pathString =
ServletContext.getRealPath("/index.html");

Could easily return:
"C:SunAppServerdomainsdomain1applicationsj2ee-mod
ulesyourwarindex.html"

That will locate a bundled file within the web app. It will
also locate files THAT DO NOT EXIST. When that happens, it
will return a path where it SHOULD be if it DID exist.

But, to be clear, this is relative to the executing WAR and
has nothing to do with the actual "docroot" of the
virtual server.

Just want to be clear on the vocabulary here.
[Message sent by forum member 'whartung' (whartung)]

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


------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribeglassfish.dev.java.net
For additional commands, e-mail: users-helpglassfish.dev.java.net


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )