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对象自动销毁。

  • 相关阅读:
    命令行参数(argc, argv)
    [转]CodeSmith和PowerDesigner的使用安装和数据库创建
    INADDR_ANY的确切含义
    C++的CreateThread实例
    浅谈VC++中预编译的头文件放那里的问题分析
    [转]Windows网络编程学习-面向连接的编程方式
    char 转wchar_t 及wchar_t转char
    connect函数详解
    正斜杠(/)与反斜杠()区别
    C/C++关于string.h头文件和string类
  • 原文地址:https://www.cnblogs.com/lls1350767625/p/7639032.html
Copyright © 2011-2022 走看看