Public class Counter
{ long count=0;
public long getCount()
{
return count;
}
public synchronized long setCount()
{count++;
return count;
}
}
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="Counter" %>
<jsp:useBean id="counter" class="Counter" scope="application">
</jsp:useBean>
<HTML>
<head>
<title>用JavaBean作网站计数器</title>
</head>
<BODY>
<% if(session.isNew())//如果是一个新的会话
counter.setCount();
%>
<P><P>欢迎访问本站,您是第
<%=counter.getCount()%>
个访问用户。
</BODY>
</HTML>