Buffalo2-HelloWord

1 下载地址: http://buffalo.sourceforge.net
2  开发环境: Eclipse3.3 + Jdk1.6+Tomcat6.0.24
3  环境配置
  3.1  将buffalo-core-2.0.jar, commons-logging-api-1.0.4.jar拷贝到WEB-INF/lib下.
  3.2  将buffalo.js, prototype.js拷贝到script下.如下图:
  3.3  在src下创建buffalo-service.properties属性文件
  3.4  在web.xml配置Buffalo的映射
<servlet>
<servlet-name>bfapp</servlet-name>
<servlet-class>
net.buffalo.web.servlet.ApplicationServlet
</servlet-class
<!—- 容器加载Buffalo的时间,越小启动越快.这里为何设置为2,在配合使用spring时会用到,加载Buffalo的时间一定要小于加载spring的时间 -->
<load-on-startup>2</load-on-startup>	
</servlet>
<servlet-mapping>
  <servlet-name>bfapp</servlet-name>
<!—-各页面初始化Buffalo时用到-->
  <url-pattern>/bfapp/*</url-pattern>
</servlet-mapping>
4 编写测试类及页面
  4.1 创建测试类,源码如下:
package net.buffalo.web;
public class HelloWord {	
   public String hello(String userName){
     return "Hello "+userName;
   }
   public String test(){
	return "Hello Word! Buffalo";
   }
}


4.2 在buffalo-service.properties添加映射:
helloService=net.buffalo.web.HelloWord
注意: buffalo-service这个名字不能修改
4.3 示例页面
   4.3.1 引入js
<script language="JavaScript" src="script/prototype.js"></script>
<script language="JavaScript" src="script/buffalo.js"></script>

4.3.2 JS代码
<script language="JavaScript">
var endPoint="<%=request.getContextPath()%>/bfapp";
var buffalo = new Buffalo(endPoint);
function helloBuffalo(){
var userName = $("userName").value;
buffalo.remoteCall("helloService.hello",[userName],function(data){
     alert(data.getResult());
  });
}	
function testBuffalo(){
	buffalo.remoteCall("helloService.test",[],function(data){
		alert(data.getResult());
	});
}
</script>

4.3.3 HTML代码

<input type="button" value="无参调用" onclick="testBuffalo();">
<input type="text" name="userName" id="userName">
<input type="button" value="有参调用" onclick="helloBuffalo();">

5 启动Tomcat,输入访问地址,OK

     
    
     
      
       

 



你可能感兴趣的:(java,tomcat,.net,Web,prototype)