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內容
<?xml version="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檔案
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//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 String getHello(String name) {
return "Hello , "+name +" 這是第一個buffalo樣本程式" ;
}
}
7.buffalo-service.properties檔案放到WEB-INF/classes/目錄下
demoService=demo.buffalo.DemoService 說明:架構是通過此檔案來尋找遠程調用的類的。
8.現在可以運行了。
樣本下載
注意:Eclipse項目,檔案編碼是UTF-8
官方地址:
Buffalo中文論壇: http://groups.google.com/group/amowa
http://buffalo.sourceforge.net/tutorial.html
http://confluence.redsaga.com/pages/viewpage.action?pageId=1643 JavaScript API : http://confluence.redsaga.com/display/BUFFALO/JavaScript+API
http://www.amowa.net/buffalo/zh/index.html