application实现网页访问计数功能
2022-09-18 16:41:21 # javaweb

用application实现一个网页计数功能,将计数器放在application中

application.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%--
Created by IntelliJ IDEA.
User: DELL
Date: 2022/9/18
Time: 16:43
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>
<%
int num;
if(application.getAttribute("num")==null){
num=0;
}
else{
num = (Integer)application.getAttribute("num");
num++;
}
application.setAttribute("num",num);
%>
<h3>页面已被访问了<%= num%>次</h3>
</body>
</html>