小编典典
您需要实现ServletContextListner接口,并在其中启动要在tomcat启动时执行的代码。
这是有关它的简短描述。
ServletContextListner在javax.servlet包中。
这是有关如何执行的简短代码。
public class MyServletContextListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
//Notification that the servlet context is about to be shut down.
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// do all the tasks that you need to perform just after the server starts
//Notification that the web application initialization process is starting
}
}
并且您需要在部署描述符web.xml中对其进行配置
mypackage.MyServletContextListener
2020-06-16