zoukankan      html  css  js  c++  java
  • java自定义监听器

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    /**
     * 监听application对象的创建和销毁
     */
    public class SystemUpInitListener implements ServletContextListener {
        Logger logger= LoggerFactory.getLogger(SystemUpInitListener.class);
    
        //当application初始化
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            //获取application
            ServletContext application = sce.getServletContext();
            //获取上下文路径
            String contextPath = application.getContextPath();
            logger.debug("当前上下文路径contextPath{}",contextPath);
            application.setAttribute("PATH",contextPath);
        }
    
        //application 销毁
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    }

    web.xml

    <!--自定义监听器 监听上下文路径-->
      <listener>
        <listener-class>com.ytkj.rose.listener.SystemUpInitListener</listener-class>
      </listener>

    jsp 页面运用

  • 相关阅读:
    python2和python3的区别
    星球大战
    [USACO]高低卡(金)High Card Low Card (Gold)
    学习笔记
    叶子的染色
    大问题
    ...
    考试前...
    [HAOI2010]计数
    [POI2006]OKR-Periods of Words
  • 原文地址:https://www.cnblogs.com/yscec/p/12374426.html
Copyright © 2011-2022 走看看