/* * CustomerListener.java * * Created on 30 November 2006, 18:44 */ package cbcc.org.listeners; import cbcc.org.listeners.Customer; import java.util.LinkedList; import java.util.List; import javax.servlet.ServletContextListener; import javax.servlet.ServletContextEvent; /** * * @author Owner * @version * * Web application lifecycle listener. */ public class CustomerListener implements ServletContextListener { /** * ### Method from ServletContextListener ### * * Called when a Web application is first ready to process requests * (i.e. on Web server startup and when a context is added or reloaded). * * For example, here might be database connections established * and added to the servlet context attributes. */ public void contextInitialized(ServletContextEvent evt) { //create list of customers List customersList = new LinkedList(); //create customers Customer c = new Customer(); Customer c2 = new Customer(); c2.setName("bob"); //add customers to list customersList.add(c); customersList.add(c2); //add list to context evt.getServletContext().setAttribute("customersList", customersList); } /** * ### Method from ServletContextListener ### * * Called when a Web application is about to be shut down * (i.e. on Web server shutdown or when a context is removed or reloaded). * Request handling will be stopped before this method is called. * * For example, the database connections can be closed here. */ public void contextDestroyed(ServletContextEvent evt) { // TODO add your code here e.g.: /* Connection con = (Connection) e.getServletContext().getAttribute("con"); try { con.close(); } catch (SQLException ignored) { } // close connection */ } }