jsp利用application统计在线人数的方法
2018-10-12 13:59
726 查看
本文实例讲述了jsp利用application统计在线人数的方法。分享给大家供大家参考。
具体实现方法如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>application</title>
</head>
<body>
<%!
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");
}
%>
<p>
<font size="2" color="blue">简单的页面访问计数器</font>
</p>
<p>
<font size="2" color="#000000">
欢迎访问此页面,您是<%=number%>个访问用户
</font>
</p>
</body>
</html>
希望本文所述对大家的jsp程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- jsp利用application统计在线人数的方法
- 利用servlet监听器实现jsp中在线人数统计的方法
- 利用servlet监听器实现jsp中在线人数统计的方法
- 【Jsp】利用Application对象实现访问人数统计功能
- ASP.NET中利用Application和Session统计在线人数、历史访问量
- php模仿asp Application对象在线人数统计实现方法
- JSP基于session,application的在线人数统计
- php模仿asp Application对象在线人数统计实现方法
- 又一种在线人数统计方法(只用1个APPLICATION,原创)
- 利用Redis统计网站在线活跃用户的方法
- 利用HttpSessionListener实现网站在线人数统计功能
- 对jsp的一个小结(8)使用servlet控制新闻管理、使用过滤器(解决乱码)和监听器(统计在线用户人数)
- Jsp统计在线人数和在线注册人数
- 利用监听器实现在线人数统计
- 在线人数的统计方法
- ASP.NET中使用Application对象实现简单在线人数统计功能
- 利用监听器实现在线人数统计
- asp.net 在线人数统计,页面访问量 Application ,session
- jsp简单实现统计在线人数
- php实现统计网站在线人数的方法