package test;

import   javax.servlet.*; 

public   class   MyCode   implements   ServletContextListener 
{ 
        //当Tomcat启动时会执行contextInitialized() 
        public   void   contextInitialized(ServletContextEvent   e) 
        { 
                new   MyThread().start(); 
        } 
        public   void   contextDestroyed(ServletContextEvent   e) 
        { 
                
        } 
        class   MyThread   extends   Thread 
        { 
                public   void   run() 
                { 
                      System.out.println("测试开始");
                } 
        } 
} 

  

web.xml 添加下面的就可以了

<listener> 
  <listnenr-class> test.MyCode </listener-class> 
</listener>

  

相关文章:

  • 2021-06-28
  • 2021-04-17
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2021-08-24
  • 2021-10-30
  • 2022-12-23
  • 2021-04-26
  • 2021-11-24
  • 2021-12-24
相关资源
相似解决方案