zoukankan      html  css  js  c++  java
  • 继承ServletContextListener可以完成的事情

    1.定时任务:

      定时任务是从某个固定的时间开始执行特定的程序,继承这个方法,可以实现刚启动项目的时候执行某特定的程序,完成给客户部署的时即可以看到某个页面的效果。

    2.初始化系统常量等:

      这样来完成系统需要的一些数据,批量完成页面需要的某些变量,

      例如:Copyright © ${copyright_year}. ${applicationScope.cropyright_name}</div>

      而且这些元素是可以批量初始化到applicationScope中去的。所以有些项目根据jsp页面中的applicationScope.cropyright_name,全文查找是找不到页面中的元素在哪里存了。

      例如:

    public void contextInitialized(ServletContextEvent servletContextEvent) {

     ServletContext servletContext = servletContextEvent.getServletContext();
    ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    SysInformationMapper sysInformationMapper = applicationContext.getBean(SysInformationMapper.class);
    SysInformationExample sysInformationExample = new SysInformationExample();
    sysInformationExample.createCriteria().andEnabledEqualTo("1");
    List<SysInformation> sysInformationList = sysInformationMapper.selectByExample(sysInformationExample);

    if(sysInformationList!=null && sysInformationList.size()>0){
    for(SysInformation sysInformation:sysInformationList){
    servletContext.setAttribute(sysInformation.getInfoSign(),sysInformation.getInfoValue());
    System.out.println(sysInformation.getInfoSign()+" >>> "+sysInformation.getInfoValue());
    }
    }
    }

    3.需要在web.xml中配置对应的listener

    <listener>
    <listener-class>com.huntech.web.listener.SystemConfigListener</listener-class>
    </listener>
  • 相关阅读:
    hdu-1162 Eddy's picture---浮点数的MST
    hdu-3371 Connect the Cities---kruskal
    hdu-1879 继续畅通工程---确定部分边的MST
    hdu-1875 畅通工程再续---MST
    hdu1863 畅通工程---MST&连通
    hdu-1233 还是畅通工程---MST模板
    hdu-1232 畅通工程---并查集
    BZOJ3940: [Usaco2015 Feb]Censoring
    BZOJ2434: [Noi2011]阿狸的打字机
    BZOJ2938: [Poi2000]病毒
  • 原文地址:https://www.cnblogs.com/wlhebut/p/7889600.html
Copyright © 2011-2022 走看看