简单判断该网页被访问了多少次

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/25
  Time: 8:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
   Object count = application.getAttribute("num");
   if(count==null){
       //如果为空则为第一次访问,将num值设置为1
       application.setAttribute("num",1);
   }else {
       //将此值转换为string类型,再强转为int类型以进行自增运算
       int i=Integer.parseInt(count+"");
       i++;
       application.setAttribute("num",i);
   }
    System.out.println("本网站访问次数为" + application.getAttribute("num"));


%>
<%=application.getAttribute("num")%>

</body>
</html>
原文地址:https://www.cnblogs.com/fanqiexin/p/11081400.html