users@glassfish.java.net

Re: Read file from docroot

From: Gabe Wong <gabrielw_at_ngasi.com>
Date: Thu, 08 Nov 2007 11:05:51 -0800

yonestar wrote:
> Kedar, Jan, and others- thanks so much for the posts and discussion!! i've
> tried some of your proposed solutions, but i'm not finding something that
> works.
>
> it seems
>
>
>
>> String pathString = ServletContext.getRealPath("/index.html");
>> Could easily return:
>> "C:\Sun\AppServer\domains\domain1\applications\j2ee-modules\yourwar\index.html"
>>
>>
>
> is exactly what i want. However, i cannot access the getRealPath method
> ("non-static method cannot be accessed from static context"). i think this
> is b/c my program is not a servlet (does not extend any servlet
> interface/class).
>

So have a servlet register the ServletContext to your program via the
init() method. That way you would have
access to the SerlvetContext outside of a Servlet. So you would be able
to call the getRealPath

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