//ready to process requests void contextInitialized (ServletContextEvent sce); //shutdown event of servlet context void contextDestroyed (ServletContextEvent sce);Basic Listener class:
public class ExampleContextListener
implements ServletContextListener {
public void contextDestroyed(ServletContextEvent event) {
System.out.println("Web app was removed.");
}
public void contextInitialized(ServletContextEvent event) {
System.out.println("Web app is ready.");
}
}
ServletContextListeners will be used as pre or post hook handlers for example to initialize configurations or other things. For example the Spring ContextLoaderListener is used for initialization of the configured Spring dependency injection on start of the web application.
After you implemented the ServletContextListener interface you have only add your class in the web.xml file.
... <listener> <listener-class>ExampleContextListener</listener-class> </listener> ...Regards
Rafael Sobek
Technorati Tags: Servlet Listener Servlet Servlet Lifecycle
