ServletContextListener接口用法

来源:互联网 发布:mac启动windows 编辑:程序博客网 时间:2024/06/05 00:54

ServletContextListener接口用于tomcat启动时自动加载函数,方法如下:
一、需加载的类必须实现ServletContextListener接口。
二、该接口中有两个方法必须实现:
1、contextInitialized(ServletContextEvent sce)该方法为服务器起动时加载内容。
2、contextDestroyed(ServletContextEvent sce)该方法为服务器关闭时加载的内容。
三、如:

public class ReadContext extends HttpServlet implements ServletContextListener{    public void  contextInitialized(ServletContextEvent sce){        System.out.println("this is contextInitialized");    }    public void contextDestroyed(ServletContextEvent sce){        System.out.println("this is contextDestroyed");    }}

四、web.xml配置listener标签

<listener>    <listener-class>ReadContext</listener-class></listener>

五、如果contextDestroyed不执行多是因为tomcat没有正常关闭或是没有实现ServletContextListener接口。在MyEclipse关闭tomcat的正确方法是:点击右键点关闭

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 鞍马寺 门前冷落鞍马稀 愿为市鞍马的市是什么意思 国初以来画鞍马 髓鞘 鞘翅 鞘怎么读 髓鞘化延迟 髓鞘化 神经鞘瘤 脱髓鞘 脑白质脱髓鞘改变 小孩鞘膜积液图片 脱髓鞘改变 脑白质脱髓鞘疾病 鞘膜积液形成 鞘翅怎么用 翅鞘 鞠义 鞠亚 鞠姓 鞠姓起名 姓鞠的男孩名字 鞠宠 鞠宠 准拟佳期 鞠毅 鞠萍 鞠萍简历 鞠萍姐姐 鞠萍讲故事 鞠萍倪萍 鞠萍歌曲 吴鞠萍 鞠萍近况 鞠萍图片 鞠萍老公 鞠萍姐姐讲故事 鞠萍素颜现身 鞠萍简历个人资料 鞠萍讲故事大全