|
(1)當(dāng)前的Wen應(yīng)用重新部署
(2)Tomcat服務(wù)器重啟
計(jì)數(shù)器要重新開始計(jì)數(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對(duì)象中有沒有保存名為count的參數(shù)
//如果沒有,在application對(duì)象中新增一個(gè)名為count的參數(shù)
if(application.getAttribute("count")==null){
application.setAttribute("count", new Integer(0));
}
Integer count = (Integer)application.getAttribute("count");
//使用application對(duì)象讀取count參數(shù)的值,再在原值基礎(chǔ)上累加1
application.setAttribute("count",new Integer(count.intValue()+1));
%>
<h2>
<!-- 輸出累加后的count參數(shù)對(duì)應(yīng)的值 -->
歡迎您訪問,本頁(yè)面已經(jīng)被訪問過(guò) <font color="#ff0000"><%=application.getAttribute("count") %></font>次。。。。
</h2>
</body>
</html>
在瀏覽器輸入:http://localhost:8888/WebDemo/count.jsp

在需要計(jì)數(shù)的jsp文件中,包含該count.jsp即可。
復(fù)制代碼 代碼如下:
<%@include file="count.jsp" %>
jsp技術(shù):application對(duì)象統(tǒng)計(jì)所有用戶對(duì)某網(wǎng)頁(yè)的訪問次數(shù),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。