本文實(shí)例講述了jsp利用application統(tǒng)計(jì)在線人數(shù)的方法。分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
%@ 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)//如果是第一個(gè)訪問者
{
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">簡(jiǎn)單的頁(yè)面訪問計(jì)數(shù)器/font>
/p>
p>
font size="2" color="#000000">
歡迎訪問此頁(yè)面,您是%=number%>個(gè)訪問用戶
/font>
/p>
/body>
/html>
希望本文所述對(duì)大家的jsp程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- jsp利用echarts實(shí)現(xiàn)報(bào)表統(tǒng)計(jì)的實(shí)例
- JS+JSP通過img標(biāo)簽調(diào)用實(shí)現(xiàn)靜態(tài)頁(yè)面訪問次數(shù)統(tǒng)計(jì)的方法
- JSP實(shí)現(xiàn)網(wǎng)頁(yè)訪問統(tǒng)計(jì)
- jsp的九大內(nèi)置對(duì)象深入講解
- springboot整合jsp,實(shí)現(xiàn)公交車站路線圖
- SpringBoot+MybatisPlus+Mysql+JSP實(shí)戰(zhàn)
- 如何將JSP/Servlet項(xiàng)目轉(zhuǎn)換為Spring Boot項(xiàng)目
- idea springboot 修改css,jsp不重啟實(shí)現(xiàn)頁(yè)面更新的問題
- Springboot集成jsp及部署服務(wù)器實(shí)現(xiàn)原理
- 教你怎么用JSP統(tǒng)計(jì)網(wǎng)站訪問人數(shù)