初玩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 <beans> 總體感覺是簡潔,無須關注xmlhttp,告別xml讓我感到有點欣慰。
posted on 2005-12-28 17:12 david.turing 閱讀(1958) 評論(1) 編輯 收藏
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
<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>