application對象統(tǒng)計所有用戶對某網(wǎng)頁的訪問次數(shù)
更新時間:2013年08月28日 16:09:39 作者:
使用application對象完成累計的功能統(tǒng)計所有用戶對某網(wǎng)頁的訪問次數(shù),具體實現(xiàn)如下,喜歡的朋友可以參考下
因為使用application對象完成累計的功能,所以當(dāng)
(1)當(dāng)前的Wen應(yīng)用重新部署
(2)Tomcat服務(wù)器重啟
計數(shù)器要重新開始計數(shù)。
jsp代碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//判斷application對象中有沒有保存名為count的參數(shù)
//如果沒有,在application對象中新增一個名為count的參數(shù)
if(application.getAttribute("count")==null){
application.setAttribute("count", new Integer(0));
}
Integer count = (Integer)application.getAttribute("count");
//使用application對象讀取count參數(shù)的值,再在原值基礎(chǔ)上累加1
application.setAttribute("count",new Integer(count.intValue()+1));
%>
<h2>
<!-- 輸出累加后的count參數(shù)對應(yīng)的值 -->
歡迎您訪問,本頁面已經(jīng)被訪問過 <font color="#ff0000"><%=application.getAttribute("count") %></font>次。。。。
</h2>
</body>
</html>
在瀏覽器輸入:http://localhost:8888/WebDemo/count.jsp
在需要計數(shù)的jsp文件中,包含該count.jsp即可。
<%@include file="count.jsp" %>
(1)當(dāng)前的Wen應(yīng)用重新部署
(2)Tomcat服務(wù)器重啟
計數(shù)器要重新開始計數(shù)。
jsp代碼如下:
復(fù)制代碼 代碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//判斷application對象中有沒有保存名為count的參數(shù)
//如果沒有,在application對象中新增一個名為count的參數(shù)
if(application.getAttribute("count")==null){
application.setAttribute("count", new Integer(0));
}
Integer count = (Integer)application.getAttribute("count");
//使用application對象讀取count參數(shù)的值,再在原值基礎(chǔ)上累加1
application.setAttribute("count",new Integer(count.intValue()+1));
%>
<h2>
<!-- 輸出累加后的count參數(shù)對應(yīng)的值 -->
歡迎您訪問,本頁面已經(jīng)被訪問過 <font color="#ff0000"><%=application.getAttribute("count") %></font>次。。。。
</h2>
</body>
</html>
在瀏覽器輸入:http://localhost:8888/WebDemo/count.jsp

在需要計數(shù)的jsp文件中,包含該count.jsp即可。
復(fù)制代碼 代碼如下:
<%@include file="count.jsp" %>
相關(guān)文章
JAVA POST與GET數(shù)據(jù)傳遞時中文亂碼問題解決方法
最近亂忙活弄了一個企業(yè)家宣傳網(wǎng)站遇到了中文字符集亂碼問題,在此分享一下即簡單又實用的解決方法,感興趣的朋友可以參考下哈2013-06-06JSP Servelet 數(shù)據(jù)源連接池的配置
在高版本的Tomcat中有的可以省略第2步,有的則不能,如果不能則會引發(fā)異常,找不到驅(qū)動類2009-07-07JSP中內(nèi)建exception對象時出現(xiàn)500錯誤的解決方法
這篇文章主要介紹了JSP中內(nèi)建exception對象時出現(xiàn)500錯誤的解決方法,以一個簡單實例形式分析了exception對象出現(xiàn)500錯誤的解決方法,涉及瀏覽器及error文件的設(shè)置技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11jsp登陸校驗演示 servlet、login、success
這篇文章主要為大家詳細(xì)介紹了jsp登陸校驗演示,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12