Hello,
 I don't know if you still need it, but the "correct" way is to add a
ServletContextListener. To do this, you have to implement the
ServletContextListener interface:

public class FooContextListener implements ServletContextListener {
        public void contextInitialized(ServletContextEvent event) {
                String homeDir = event.getServletContext().getRealPath("");
        }

        public void contextDestroyed(ServletContextEvent event) {
        }
}

and declare it in the web.xml:

<web-app>

        <listener>

                <listener-class>

                        FooContextListener

                </listener-class>

        </listener>
...
</web-app>

The contextInitialized() method is called when your webapp starts. The
contextDestroyed() is called before the webapp stops and you can use
it to add any cleanup code you wish.

cheers,
Antonis


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.

Thanks in advance

Patrice



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to