web listener development process

development process:

** a) Write a common class to implement the corresponding interface, that is, the event listener
b) Register the event listener in the web.xml file

** ## Life cycle: ** Null parameter construction (1 time) -> initialization (1 time) -> destruction (1 time), it is a singleton mode that is generated when deploying web applications, that is, the first time the user The access has been generated before. When the web application is redeployed, the original listener will be destroyed, and a new listener will be generated.** ## web.xml ``` cn.xijie.listener.MyServletContextListener ```` # java code``` import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; //Event listener [used to monitor the generation and destruction of ServletContext objects] public class MyServletContextListener implements ServletContextListener { public MyServletContextListener(){ System .out.println("null parameter construction"); System.out.println(this.hashCode()); } @Override //Generate public void contextDestroyed(ServletContextEvent arg0) { System.out.println("ServletContext generated") ; System.out.println(this.hashCode()); } @Override //Destroy public void contextInitialized(ServletContextEvent arg0) { System.out.println("ServletContext Destroy"); System.out.println(this.hashCode( )); } } ```

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324587600&siteId=291194637