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>