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

          [運(yùn)行結(jié)果]


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

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 武强县| 恩施市| 灵璧县| 会宁县| 东山县| 桦甸市| 孝昌县| 毕节市| 东城区| 常德市| 华宁县| 土默特左旗| 通江县| 贵德县| 杂多县| 景东| 新疆| 新源县| 化隆| 白玉县| 西昌市| 随州市| 五大连池市| 准格尔旗| 始兴县| 静安区| 凤庆县| 松阳县| 深水埗区| 英吉沙县| 高邮市| 潼南县| 清河县| 信宜市| 曲靖市| 乃东县| 天峻县| 和林格尔县| 金溪县| 夏邑县| 惠东县|