<html>
<head>
<title>Applcation object in JSP</title>
</head>
<body>
<%
Integer Count =
(Integer)application.getAttribute("Counter");<span style="color:#3333ff;">//Count默认值为 0</span>
if( Count ==null || Count == 0 ){
/* 第一次访问 */
out.println("Welcome to my website!");
Count = 1;
}else{
/* 返回访问值 */
out.println("Welcome back to my website!");
Count += 1;
}
application.setAttribute("Counter", Count);<span style="color:#3333ff;">//设置参数Count ,不能直接设置为数字 1 等;</span>
%>
<center>
<p>Total number of visits: <%= hitsCount%></p>
</center>
</body>
</html>
</pre><pre name="code" class="html">
application语法结构:
application.setAttribute(String Key, Object Value);
application.getAttribute(String Key);