jsp利用application統(tǒng)計在線人數(shù)的方法
更新時間:2015年01月05日 11:01:18 投稿:shichen2014
這篇文章主要介紹了jsp利用application統(tǒng)計在線人數(shù)的方法,代碼中備有較為詳盡的注釋便于理解,是比較實用的技巧,需要的朋友可以參考下
本文實例講述了jsp利用application統(tǒng)計在線人數(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)//如果是第一個訪問者
{
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">簡單的頁面訪問計數(shù)器</font>
</p>
<p>
<font size="2" color="#000000">
歡迎訪問此頁面,您是<%=number%>個訪問用戶
</font>
</p>
</body>
</html>
<%
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">簡單的頁面訪問計數(shù)器</font>
</p>
<p>
<font size="2" color="#000000">
歡迎訪問此頁面,您是<%=number%>個訪問用戶
</font>
</p>
</body>
</html>
希望本文所述對大家的jsp程序設(shè)計有所幫助。
您可能感興趣的文章:
- jsp利用echarts實現(xiàn)報表統(tǒng)計的實例
- JS+JSP通過img標(biāo)簽調(diào)用實現(xiàn)靜態(tài)頁面訪問次數(shù)統(tǒng)計的方法
- JSP實現(xiàn)網(wǎng)頁訪問統(tǒng)計
- jsp的九大內(nèi)置對象深入講解
- springboot整合jsp,實現(xiàn)公交車站路線圖
- SpringBoot+MybatisPlus+Mysql+JSP實戰(zhàn)
- 如何將JSP/Servlet項目轉(zhuǎn)換為Spring Boot項目
- idea springboot 修改css,jsp不重啟實現(xiàn)頁面更新的問題
- Springboot集成jsp及部署服務(wù)器實現(xiàn)原理
- 教你怎么用JSP統(tǒng)計網(wǎng)站訪問人數(shù)
相關(guān)文章
利用jsp+Extjs實現(xiàn)動態(tài)顯示文件上傳進度
這篇文章主要介紹了利用jsp+Extjs實現(xiàn)動態(tài)顯示文件上傳進度。需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12
JSP組件commons-fileupload實現(xiàn)文件上傳
這篇文章主要為大家詳細介紹了JSP組件commons-fileupload實現(xiàn)文件上傳,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
JSP教程之使用JavaBean完成業(yè)務(wù)邏輯的方法
這篇文章主要介紹了JSP教程之使用JavaBean完成業(yè)務(wù)邏輯的方法,較為詳細的分析了JavaBean完成業(yè)務(wù)邏輯所涉及的相關(guān)概念及使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09
JSP開發(fā)Servlet重寫init()方法實例詳解
這篇文章主要介紹了JSP開發(fā)Servlet重寫init()方法實例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04
詳解Struts2中對未登錄jsp頁面實現(xiàn)攔截功能
這篇文章主要介紹了Struts2中對未登錄jsp頁面進行攔截功能的實現(xiàn),在演示源碼的同時對步驟和原理進行了分析,具有一定參考價值,需要得朋友可以了解下。2017-09-09

