JavaWeb-ServletContextListener

匿名 (未验证) 提交于 2019-12-02 21:52:03

ServletContextListener:

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

2)how:

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

implements ServletContextListener

  > 在web.xml文件中配置Listener

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

 

4) API:

  

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

  

1) 和ServletContextListener类似

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!