<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>统计页面访问次数</title>
</head>
<body>
<%
//step1 获得本页面已经被访问的次数
Object temp= application.getAttribute("count");
int count=0; //本页面的访问次数
if(temp!=null){ //此页面不是第一次访问
count=(Integer)temp;
count++; //step2 不是第一次访问,次数+1
}else {
//此页面是第一次访问 ,application中没有保存访问次数,此时该值就是null
count = 1;
}
//step3 保存最近的访问次数
application.setAttribute("count",count);
%>
本页面的访问次数是:<%=count%>
本文介绍了一种使用Java和JSP技术实现的网页访问计数器。通过在应用服务器上维护一个计数变量来记录页面被访问的总次数,并且每次用户访问页面时都会更新这个计数器。
840

被折叠的 条评论
为什么被折叠?



