posts - 44,  comments - 48,  trackbacks - 0
          ??? 本實例實現一個簡單的網站計數器
          ??? [編程要點]
          ??? 這里主要用到了Java2的同步處理機制,每個Java application 都有basic.counter的屬性,當application被調用一次就把basic.counter值加1.
          ?? ?[程序實現]
          <%@ page contentType="text/html; charset=gb2312" %>
          <%@ page language="java" %>
          <%
          ? Integer count = null;
          ? //同步處理
          ?
          synchronized (application)
          ? {
          ??? //從內存當中讀取訪問量
          ??? count = (Integer) application.getAttribute("basic.counter");
          ??? if (count == null)
          ??? count = new Integer(0);
          ??? count = new Integer(count.intValue() + 1);
          ??? //將訪問量保存到內存當中
          ??? application.setAttribute("basic.counter", count);
          ? }
          %>?
          <html>
          <head>
          <title>簡單計數器</title>
          </head>
          <body>
          <center>
          <font size=10 color=blue>簡單計數器</font>
          <br>
          <hr>
          <br>
          <font size=5 color=blue>您好!您是本站的第 <%= count %> 位客人</font>
          </center>
          </body>
          </html>

          [運行結果]


          {41104DB0-9104-4E70-BE06-CBAB52A5E206}.BMP
          posted on 2006-08-21 12:16 摩西 閱讀(1076) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 海城市| 六盘水市| 肥乡县| 雷州市| 乐昌市| 武平县| 饶平县| 车险| 无极县| 夹江县| 莱阳市| 蓝山县| 邻水| 郁南县| 西峡县| 延庆县| 商都县| 清水河县| 东乡族自治县| 大荔县| 广州市| 日照市| 高雄市| 保靖县| 黄浦区| 克什克腾旗| 石棉县| 克山县| 綦江县| 上栗县| 攀枝花市| 垣曲县| 政和县| 建水县| 海城市| 抚松县| 民权县| 舒城县| 平远县| 东丽区| 镇原县|