How to use servletContextListener

xiaoxiao2021-04-10  386

This J2EE tip describes the usage of servletContextListener. This event class is a notification of the WEB application service to process the WEB application's CRVLET context. This can be explained as if someone constantly informing us what the server happens next to the server. That of it is of course a listener. Therefore, the servletContextListner is very useful when notifying the context (context) initialization and destruction.

import javax.servlet.ServletContextListener; import javax.servlet.ServletContextEvent; import javax.servlet *;. public class MyListener implements ServletContextListener {private ServletContext context = null; / * This method is removed in a Web service application, there is no ability to accept requests Time called. * / Public void contextDestroyed (ServletContextEvent event) {// Output a simple message to the server's console System.out.println ( "The Simple Web App Has Been Removed."); This.context = null;} // This method The web application service is called when the request is accepted. public void contextInitialized (ServletContextEvent event) {this.context = event.getServletContext (); // Output a simple message to the server's console System.out.println ( "The Simple Web App Is Ready.");}} com.listeners.mycontextListener

转载请注明原文地址:https://www.9cbs.com/read-133236.html

New Post(0)