当前位置:主页 > 查看内容

jsp利用application统计在线人数的方法

发布时间:2021-06-07 00:00| 位朋友查看

简介:本文实例讲述了jsp利用application统计在线人数的方法。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下: %@ page language="java" import="java.util.*" pageEncoding="UTF-8"% % String path = request.getContextPath(); String basePath =……

本文实例讲述了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程序设计有所帮助。


本文转载自网络,原文链接:https://m.jb51.net/article/59446.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐