风中小郎君

导航

tomcat启动自动执行代码

可以添加Tomcat的 listener 
在web.xml中添加listener节点 

Xml代码  
  1. <listener>  
  2.     <listener-class>com.PreloadListener</listener-class>  
  3. </listener>  



java代码: 

Java代码  
  1. public class PreloadListener implements ServletContextListener{  
  2.   public void contextInitialized (ServeltContextEvent sce){  
  3.      //init operation  在此填写自己要加的代码程序main方法的内容
  4.   }  
  5.   public void contextDestoryed (ServeltContextEvent sce){  
  6.      //destory operation  
  7.   }  
  8. }  

posted on 2015-07-10 13:28  风中小郎君  阅读(146)  评论(0)    收藏  举报