<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);
本文详细解释了如何使用JSP应用对象实现计数器功能,包括如何设置和获取属性,以及如何根据访问次数显示不同的欢迎消息。
1690

被折叠的 条评论
为什么被折叠?



