首页 > 移动平台 > 详细

application————web

时间:2019-03-10 15:18:19      阅读:164      评论:0      收藏:0      [点我收藏+]

application

  作用域:

    只要web服务器不关闭就一直存在

 

统计页面的统计次数

   一个用户 多次刷新也统计

  多个用户访问

思路:

  需要一个变量 count 记录index.jsp访问次数

方法

   public void setAttribute(String name,Object obj);

  public Object getAttrbute(String name );

 

【统计页面】

 

<%
//实现访问次数的统计
//1、先获取applicationd的属性值
Object count =application.getAttribute("count");
if(count==null){
//2、用户第一次访问 application没有这个值,所以设置一个application
application.setAttribute("count",1);
}else{
//3、用户第二次以上访问,已经有了application这个值,所以需要再原基础上再叠加+1
Integer intCount = (Integer) count;
application.setAttribute("count",intCount+1);
}
//将值取出来
Integer icount=(Integer)application.getAttribute("count");
//打印
out.print("访问次数是:"+icount);


%>

 

application————web

原文:https://www.cnblogs.com/xinjingsiyuan/p/10505317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!