Servlet context listener
ServletContextListener
WebListenerpublic class ServletContextListenerDemo implements ServletContextListener {@ Override public void contextInitialized (ServletContextEvent servletContextEvent) {} @ Override public void contextDestroyed (ServletContextEvent servletContextEvent) {}}
ServletContextAttributeListener
WebListenerpublic class ServletContextAttributeListenerDemo implements ServletContextAttributeListener {@ Override public void attributeAdded (ServletContextAttributeEvent servletContextAttributeEvent) {} @ Override public void attributeRemoved (ServletContextAttributeEvent servletContextAttributeEvent) {} @ Override public void attributeReplaced (ServletContextAttributeEvent servletContextAttributeEvent) {}}
Description: servletContext context listener is the context that the whole application loads when it starts. A web application will have only one context. Therefore, servletContext is effective for the whole process of appliction.