实现ServletContextListener接口
ServletContextListener接口有两个方法contextInitialized和contextDestoryd分别在应用启动和销毁时执行
在应用启动时以下方法会被调用:
void contextInitialized(ServletContextEvent sce);
在应用注销时以下方法会被调用:
void contextDestoryd(ServletContextEvent sce);
在Web.xml中加入
<listener>
<listener-class>完整类名(如cn.myweb.listener.InitListener)</listener-class>
</listener>