count.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Object num1=this.getServletContext().getAttribute("count");
if(num1==null){
num1=1;
this.getServletContext().setAttribute("count",num1);
}else{
int num2=(int)num1;
num2++;
this.getServletContext().setAttribute("count",num2);
}
%>
<h1>您是当前网页第<%=this.getServletContext().getAttribute("count") %>位访问者</h1>
</body>
</html>
这是文件所在位置
- 添加到tomcat服务器上
- 运行服务器
- 在浏览器上输入http://127.0.0.1:8080/demo1118/count.jsp