首先一个类要实现ServletContextListener接口:如下
public class ServiceStartConfig implements
ServletContextListener{
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
System.out.println("监听销毁。。。。。。。。。");
}
public void contextInitialized(ServletContextEvent sce)
{
// TODO Auto-generated method stub
System.out.println("监听启动。。。。。。。。。");
}
}
其次:要在Web.xml文件里面配置一下,
com.qiang.listener.ServiceStartConfig
就可以了。
比较详细的可以查看如下链接:失落的小镇的博客
http://blog.sina.com.cn/s/blog_6810dfc20101ipzq.html
本文介绍了一个简单的ServletContextListener接口实现案例,通过创建ServiceStartConfig类并在Web.xml中进行配置,实现应用启动与销毁时的监听操作。
2878

被折叠的 条评论
为什么被折叠?



