David.Turing's blog

           

          初玩Buffalo

          頁面調用服務器的一個類里面的方法,做下面的步驟就可以了,前提是你配置好了buffalo那個demo。
          只需執行下面三個步驟,就可以完成一個簡單的乘法調用。

          =====================
          Spring例子(使用于1.2以前的版本)
          =====================
          1)  HTML頁面上
          /buffalo/WebContent/pages/simple.html


          增加頁面輸入框

          <h4>1 Multipy calculator</h4>
          <p>
            <input name="double4" type="text" class="input_text" id="double4" size="12">
            *
            <input name="double5" type="text" class="input_text" id="double5" size="12">
            <input type="button" name="Submit" value=" = " onclick="cmdMulitply()">
            <input name="double6" type="text" class="input_text" id="double6">
          </p>

          增加JS調用
          function cmdMulitply(){
             var double4 =parseFloat(Buffalo.getElementById("double4").value);
             var double5 =parseFloat(Buffalo.getElementById("double5").value);
             var d6Handle =Buffalo.getElementById("double6");
            
             buffalo.remoteCall("hnisi_service.multiply",[double4,double5], function(reply) {
            d6Handle.value = reply.getResult();
            
            alert(reply.getResult());
           })
          }


          2)/buffalo/JavaSource/demo/buffalo-service.properties文件
          加入
          # 調整所有的Service
          hnisi_service=net.buffalo.demo.hnisi.HnisiService

          3)/buffalo/JavaSource/demo/net/buffalo/demo/hnisi/HnisiService.java
          增加multiply方法

          package net.buffalo.demo.hnisi;

          public class HnisiService {

           public double multiply(double a, double b) {
            System.out.println("Calling Multipy...,a="+a+", b="+b+"    結果="+a*b);
            try {
             Thread.sleep(1000);
            } catch (Exception e) {
             e.printStackTrace();
            }
            return a*b;
           }
          }


          =====================
          Spring例子
          =====================
          Buffalo的1.2版本加入了Spring功能,如果你想使用Spring特性,上述的過程如下:
          1)  HTML頁面上
          /buffalo/WebContent/pages/simple-spring-2.html

          增加頁面輸入框

          <h4>1 Multipy calculator</h4>
          <p>
            <input name="double4" type="text" class="input_text" id="double4" size="12">
            *
            <input name="double5" type="text" class="input_text" id="double5" size="12">
            <input type="button" name="Submit" value=" = " onclick="cmdMulitply()">
            <input name="double6" type="text" class="input_text" id="double6">
          </p>

          增加JS調用
          function cmdMulitply(){
             var double4 =parseFloat(Buffalo.getElementById("double4").value);
             var double5 =parseFloat(Buffalo.getElementById("double5").value);
             var d6Handle =Buffalo.getElementById("double6");
            
             buffalo.remoteCall("hnisi_service.multiply",[double4,double5], function(reply) {
            d6Handle.value = reply.getResult();
            
            alert(reply.getResult());
           })
          }


          2)/buffalo/JavaSource/demo/buffalo-service.properties文件
          加入
          # 調整所有的Service
          hnisi_service=net.buffalo.demo.hnisi.HnisiService

          3)/buffalo/JavaSource/demo/net/buffalo/demo/hnisi/HnisiService.java
          增加multiply方法

          package net.buffalo.demo.hnisi;

          public class HnisiService {

           public double multiply(double a, double b) {
            System.out.println("Calling Multipy...,a="+a+", b="+b+"    結果="+a*b);
            try {
             Thread.sleep(1000);
            } catch (Exception e) {
             e.printStackTrace();
            }
            return a*b;
           }
          }

          4)修改/buffalo/WebContent/WEB-INF/applicationContext.xml
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "

          <beans>
           
           <bean name="simpleService" class="net.buffalo.demo.simple.SimpleService"></bean>
           <bean name="hnisiService" class="net.buffalo.demo.hnisi.HnisiService"></bean>
           <bean name="numberService" class="net.buffalo.demo.numberguess.NumberGuessService"></bean>
           
           <bean name="buffaloConfigBean" class="net.buffalo.service.BuffaloServiceConfigurer">
            <property name="services">
                      <map>
                          <entry key="springSimpleService">
                              <ref bean="simpleService"/>
                          </entry>
               <entry key="springNumberService">
                              <ref bean="numberService"/>
                          </entry>
                          <entry key="springHnisiService">
                           <ref bean="hnisiService"/>
                          </entry>
                      </map>
                  </property>
           </bean>
           
          </beans>

          總體感覺是簡潔,無須關注xmlhttp,告別xml讓我感到有點欣慰。

           

           

          posted on 2005-12-28 17:12 david.turing 閱讀(1964) 評論(1)  編輯  收藏

          評論

          # re: 初玩Buffalo 2005-12-28 18:33 胡子魚

          呵,原來你是這么玩過來的!  回復  更多評論   


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(110)

          我參與的團隊

          隨筆分類(126)

          隨筆檔案(155)

          文章分類(9)

          文章檔案(19)

          相冊

          搜索

          積分與排名

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 佛冈县| 喜德县| 永清县| 宜都市| 肇庆市| 德安县| 宜兰县| 遵义市| 元朗区| 佛坪县| 聊城市| 临澧县| 日喀则市| 唐山市| 恭城| 泽普县| 晴隆县| 漳州市| 定兴县| 峨边| 阳朔县| 资阳市| 平湖市| 宝清县| 肃北| 滁州市| 台中县| 扶沟县| 凤台县| 宁河县| 建宁县| 陆川县| 洛南县| 普兰店市| 乌兰县| 浙江省| 富裕县| 惠东县| 佛山市| 枝江市| 梁山县|