Class WebAppRootListener

All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public class WebAppRootListener
extends java.lang.Object
implements javax.servlet.ServletContextListener

Listener that sets a system property to the web application root directory. The key of the system property can be defined with the "webAppRootKey" init parameter at the servlet context level (i.e. context-param in web.xml), the default key is "webapp.root".

Can be used for toolkits that support substition with system properties (i.e. System.getProperty values), like Log4J's ${key} syntax within log file locations.

Note: This listener should be placed before ContextLoaderListener in web.xml, at least when used for Log4J.

Note: Log4jConfigListener sets the system property implicitly, so there's no need for this listener in addition to it.

WARNING: Some containers like Tomcat do NOT keep system properties separate per web app. You have to use unique "webAppRootKey" context-params per web app then, to avoid clashes. Other containers like Resin do isolate each web app's system properties: Here you can use the default key (i.e. no "webAppRootKey" context-param at all) without worrying.

Juergen Hoeller
See Also:
WebUtils.setWebAppRootSystemProperty(javax.servlet.ServletContext), Log4jConfigListener

Constructor Summary
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent event)
 void contextInitialized(javax.servlet.ServletContextEvent event)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public WebAppRootListener()
Method Detail


public void contextInitialized(javax.servlet.ServletContextEvent event)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener


public void contextDestroyed(javax.servlet.ServletContextEvent event)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

Rod Johnson and Spring contributors 2001-2003.