users@glassfish.java.net

Re: Read file from docroot

From: Gabe Wong <gabrielw_at_ngasi.com>
Date: Tue, 06 Nov 2007 12:13:01 -0800

glassfish_at_javadesktop.org wrote:
> Thanks for correcting, Jan.
>
> But since docroot is not part of any context, it won't be possible to use
> this technique to read/write files from docroot.
>
> So, I guess the only solution is to use ClassLoader.getResourceAsStream() and then
> passing the relative path. Is that right?
>
> Thanks,
> Kedar
docroot is a context. Just so happens the context path is "" or "/".

To retrieve the file path of a resource within the docroot context (I am
assuming that is where you are running your application),
use the ServletContext.getRealPath("/index.html") method.
||

-- 
Regards
Gabe Wong
NGASI AppServer Manager
Application server installation and configuration AUTOMATION
http://www.ngasi.com