Buffalo Ajax框架使用

 

buffalo-2.0(国人开发的Ajax框架),下载buffalo-2.0-bin就可以了,个人认为也下载buffalo-2.0-src
下载地址:http://sourceforge.net/project/showfiles.php?group_id=178867

1.buffalo-2.0.jar
在buffalo-2.0-bin里,把它加到Web应用程序里的lib

2.buffalo.js和prototype.js
我把这两个文件放到Web应用程序的scripts/目录下,buffalo.js在buffalo-2.0-bin里,prototype.js在buffalo-demo.war里找
4.web.xml内容

<? xmlversion="1.0"encoding="UTF-8" ?>
< web-app version ="2.4"
xmlns
="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>


< servlet >
< servlet-name > bfapp </ servlet-name >
< servlet-class > net.buffalo.web.servlet.ApplicationServlet </ servlet-class >
</ servlet >
< servlet-mapping >
< servlet-name > bfapp </ servlet-name >
< url-pattern > /bfapp/* </ url-pattern >
</ servlet-mapping >

</ web-app >

5.index.jsp文件

<% @pagelanguage = " java " pageEncoding = " UTF-8 " %>


<! DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" >
< html >
< head >
< title > 第一个buffalo示例程序 </ title >
< script language ="JavaScript" src ="scripts/prototype.js" ></ script >
< script language ="JavaScript" src ="scripts/buffalo.js" ></ script >
< script type ="text/javascript" >
var endPoint = " <%=request.getContextPath()%>/bfapp " ;

var buffalo = new Buffalo(endPoint);
function hello(me){
buffalo.remoteCall(
" demoService.getHello " ,[me.value], function (reply){
alert(reply.getResult());
})
}
</ script >
</ head >

< body >
输入你的名字:
< input type ="text" name ="myname" >
< input type ="button" value ="Buffao远程调用" onclick ="hello($('myname'));" >< br >
</ body >
</ html >


说明:remoteCall是远程调用方法,demoService是buffalo-service.properties文件的键,getHello是被调用java类方法名,me.value是传给getHello方法的参数,reply.getResult()是getHello返回的值。

6.DemoService.java文件

package demo.buffalo;

/**
*
*@文件名demo.buffalo.DemoService.java
*@作者chenlb
*@创建时间2007-7-14下午12:42:17
*/
public class DemoService{

public StringgetHello(Stringname){
return " Hello, " + name + " 这是第一个buffalo示例程序 " ;
}
}


7.buffalo-service.properties文件放到WEB-INF/classes/目录下

demoService = demo.buffalo.DemoService

说明:框架是通过此文件来查找远程调用的类的。

8.现在可以运行了。

你可能感兴趣的:(Buffalo Ajax框架使用)