zoukankan      html  css  js  c++  java
  • JSP 0710:jsp内置对象之application

    <1>  什么是application?

    application 代表整个web程序, 整个服务器端只存在一个application对象, 当Tomcat启动的时候就被创建

    application 的生命周期与Tomcat 同步

     <2>  使用application储存网站当前登录人数, 并显示在首页

        1.  在login_do中:

        <%

          if(user == null){

            // 登录失败, 略

          }else{

            // 登陆成功

            int number =  0;               

            if(application.getAttribute("userNumber") != null){      // 为了避免返回空值而产生的错误

              number = (Integer)application.getAttribute("userNumber");

            }

            number++;         

            application.setAttribute("userNumber",number);

          }

          2.  在index.jsp中:

          <%

            Object o2 = application.getAttribute("userNumber");

            if(o2 != null){

              out.println("当前登录用户: " + o2 + "个!<br/>")

            }

          %>    

    效果:

     

     

     

     

     

  • 相关阅读:
    python中列表排序的方法
    pyrhon3中字符串方法
    python数据探索与数据与清洗概述
    2020年日期表-python实现
    python中字符串离散化的例子
    python中常见的日期处理方法
    如何简单地理解Python中的if __name__ == '__main__'
    我的老爸老了
    关于
    关于
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13492125.html
Copyright © 2011-2022 走看看