jsp利用application统计在线人数的方法_附源码
来源:
中文源码网 浏览:323 次 日期:2024-05-06 14:57:40
【下载文档: jsp利用application统计在线人数的方法_附源码.txt 】
jsp利用application统计在线人数的方法
本文实例讲述了jsp利用application统计在线人数的方法。分享给大家供大家参考。
具体实现方法如下:
复制代码 代码如下:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
application<%!
Integer number;//
synchronized void numberVisiter()
{
ServletContext application = getServletContext();
Integer num = (Integer)application.getAttribute("count");
if(num == null)//如果是第一个访问者
{
num = new Integer(1);
application.setAttribute("count",num);
}
else
{
num = new Integer(num.intValue() + 1);
application.setAttribute("count",num);
}
}
%>
<%
if(session.isNew())
{
numberVisiter();
Integer number = (Integer)application.getAttribute("count");
}
%>
简单的页面访问计数器
欢迎访问此页面,您是<%=number%>个访问用户
希望本文所述对大家的jsp程序设计有所帮助。