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

<%--
  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>

 

posted @ 2019-06-25 10:35  织式  阅读(578)  评论(0编辑  收藏  举报