码迷,mamicode.com
首页 > 其他好文 > 详细

buffalo之hello world

时间:2014-09-20 17:39:19      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:buffalo

一个国产的ajax框架,定义了Web远程调用的传输基础,

并且将远程调用对象完整的序列化到了本地,成为可以被JavaScript编程触及的对象。


配置依赖包:

<dependency>
			<groupId>net.buffalo</groupId>
			<artifactId>buffalo</artifactId>
			<version>2.0</version>
		</dependency>

注:由于我是手动安装到maven本地仓库,自定义一个坐标,你也可以直接放到WEB-INF/lib下


配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">

	<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>



HelloService:

package com.demo;

public class HelloService {
	public String sayHi(String name){
		System.out.println("hello "+name);
		return "hello world";
	}
}


配置文件;

buffalo-service.properties:

#
# Buffalo Service Config

helloService=com.demo.HelloService


引入js:

<script language="JavaScript" src="js/prototype.js"></script>
<script language="JavaScript" src="js/buffalo.js"></script>


index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript" src="js/prototype.js"></script>
<script language="JavaScript" src="js/buffalo.js"></script>
<script type="text/javascript">
var endPoint="<%=request.getContextPath()%>/bfapp";
function callFn(){
	var buffalo = new Buffalo(endPoint);
	buffalo.remoteCall("helloService.sayHi",["sang"], function(reply) {
		alert(reply.getResult());
	});
}

</script>
</head>
<body>
<button onclick="callFn();">test</button>
</body>
</html>


结果:

bubuko.com,布布扣

buffalo之hello world

标签:buffalo

原文地址:http://blog.csdn.net/wobendiankun/article/details/39432563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!