zoukankan      html  css  js  c++  java
  • ServletContextListener接口用法

    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的正确方法是:点击右键点关闭

  • 相关阅读:
    Ubuntu下多版本软件的管理
    关于高考
    Openca安装笔记
    Nginx+uwsgi+python配置
    cpabe的安装
    线形同余法求随机数
    world wind 之 applet 篇
    0909 海贼王我当定了
    实验0:了解和熟悉操作系统
    0316复利计算器3.0
  • 原文地址:https://www.cnblogs.com/jpfss/p/9765582.html
Copyright © 2011-2022 走看看