zoukankan      html  css  js  c++  java
  • application对象

    统计网站访问人数代码(对于统计网站访问人数,需要判断是否是一个新访问用户)

     <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <html>
      <head>
        <title>统计网站访问人数及当前在线人数</title>
      </head>
     
      <body>
         <%! Integer yourNumber=new Integer(0); %>
         <%  if(session.isNew()){   //如果是一个新的会话
           Integer number=(Integer)application.getAttribute("Count");
            if(number==null){      //第一个访问该网站的用户
             number=new Integer(1);
            }
            else{
             number=new Integer(number.intValue()+1);
            }
            application.setAttribute("Count", number);
            yourNumber=(Integer)application.getAttribute("Count");
           }
         %>
         欢迎访问该网站,您是第<%=yourNumber%>个访问用户,
      </body>
    </html>

    application对象、request对象、session对象的区别:

    (1)session对象与用户会话相关,不同用户的session是完全不同的对象,在session中设置的属性只是在当前客户的会话范围内容有效,客户超过保存时间不发送请求时,session对象将被回收。

    (2)所有访问统一网站的用户,都有一个相同的application对象,只要关闭服务器后,application对象中设置的属性才被回收。

    (3)当客户端提交请求时,才创建request对象,当返回响应处理后,request对象自动销毁。

  • 相关阅读:
    python之路
    go mod
    黑苹果流程
    mac go配置,环境配置
    mac重装系统
    多级分销概念 MongoDB||MySQL
    MongoDB查询mgov2的聚合方法
    linux被当矿机排查案例
    docker-compose容器中redis权限问题
    docker-compose中redis查询版本
  • 原文地址:https://www.cnblogs.com/lls1350767625/p/7639032.html
Copyright © 2011-2022 走看看