Using the Servletcontextlistener Listener
There is a Servletcontextlistener interface in the Servlet API that listens to the life cycle of a ServletContext object, which is actually
Monitor the life cycle of web apps
When the servlet container starts or terminates, the Servletcontextevent event is triggered, and the event is handled by Servletlistener, in Servletcontextlistener
Two methods for handling Servletcontextevent events are defined in the interface
Contextinitialized (Servletcontextevent SCE): This method is called when the servlet container launches the Web app, after the method is called
The container is then initialized to the filter and is initialized to the servlet that needs to be initialized when the Web application starts.
Contextdestroyed (Servletcontextevent SCE): This method is called when the Serlvet container terminates the Web app, before the method is called
The container will destroy all Serlvet and filter filters
Using the Servletcontextlistener Listener