zoukankan      html  css  js  c++  java
  • JavaWeb-ServletContextListener

    ServletContextListener:

    1)what:监听ServletContext对象被创建或被销毁的Servlet监听器

    2)how:

      > 创建一个实现了ServletContextListener的类,并且实现其中的两个方法

      public class HelloServletContextListener implements ServletContextListener

      > 在web.xml文件中配置Listener

      <listener>
        <listener-class>listener.HelloListener</listener-class>
      </listener>
    

     3)why:ServletContextListener 是最常用的Listener,可以在当前web应用被加载时对当前web应用的相关资源进行初始化操作:创建数据库连接池,创建Spring的IOC容器,读取当前WEB应用的初始化参数。。。 

    4) API:

      

       //ServletContext对象被创建(即,当前WEB应用被加载时)的时候,Servlet容器调用该方法。 
      @Override public void contextInitialized(ServletContextEvent sce) { }
      //ServletContext对象被销毁之前(即,当前WEB应用被卸载时)的时候,Servlet容器调用该方法 @Override public void contextDestroyed(ServletContextEvent sce) { }
       ServletContextEvent中的:getServletContext()获取ServletContext

      

    ServletRequestListener & HttpSessionListener 

    1) 和ServletContextListener类似

  • 相关阅读:
    knowledge_maven
    problems_springboot
    problems_halo
    skills_oracle
    hive启动报错(整合spark)
    根据父ID聚合
    sql2005数据库远程备份
    waitfor的使用
    CTE+操作性语句(删除无主键的相同的多行数据)+CTE操作技巧
    SQL中的CTE,查询所有的子集(子集的子集)比游标效率高
  • 原文地址:https://www.cnblogs.com/yangHS/p/11220341.html
Copyright © 2011-2022 走看看