程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp利用application統計在線人數的方法,jspapplication

jsp利用application統計在線人數的方法,jspapplication

編輯:關於JSP

jsp利用application統計在線人數的方法,jspapplication


本文實例講述了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程序設計有所幫助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved