页面调用服务器的一个类里面的方法,做下面的步骤就可以了,前提是你配置好了buffalo那个demo。
只需执行下面三个步骤,就可以完成一个简单的乘法调用。
=====================
Spring例子(使用于1.2以前的版本)
=====================
1) HTML页面上
/buffalo/WebContent/pages/simple.html
增加页面输入框
1 Multipy calculator
*
增加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
增加页面输入框
1 Multipy calculator
*
增加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
总体感觉是简洁,无须关注xmlhttp,告别xml让我感到有点欣慰。