On 11/3/06, Craig McClanahan <[EMAIL PROTECTED]> wrote:
On 11/3/06, Patrice Le Cozler <[EMAIL PROTECTED]> wrote: > > Hi, > I want to load a property file at webapp start. Since that property file > is > located in my webapp's directory structure, I want to be able to determine > its absolute name at runtime. > I tried "this.getServlet().getServletContext().getRealPath(PROPS_FILE)" > but > "getServlet()" returns null when called from an Action constructor. > Why ? > Is there another way to achieve the same result ? I can't use > MessageResources because it depends on the actual httpRequest instance. An alternative approach that doesn't need access to the servlet instance should work for you. Put your properties file (say, "myprops.properties" in the WEB-INF/classes directory. Now, you can access it like this: InputStream stream = this.getClass().getResourceAsStream(" myprops.properties"); Properties props = new Properties(); props.load(stream); stream.close();
Exactly what I need ! Thanks Thanks in advance
> > Patrice Craig