Java web ch03_14_applicatin.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>统计网站访问人数及其当前在线人数</title>
</head>
<body>
<%! Integer yourNumber=new Integer(0); %>
<% if(session.isNew()){ //如果是一个新的会话
Integer number=(Integer) application.getAttribute("Count");
if(number == null) //如果是第1个访问网站
{ number = new Integer(1); }
else
{ number = new Integer(number.intValue()+1);}
application.setAttribute("Count",number);
yourNumber = (Integer)application.getAttribute("Count");
}
%>
欢迎访问本站,您是第 <%=yourNumber%>个访问用户。
</body>
</html>
运行
在浏览器再运行