首页 > 代码库 > buffalo之hello world

buffalo之hello world

一个国产的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=http://www.mamicode.com/"js/prototype.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=http://www.mamicode.com/"js/prototype.js"></script>>

结果:


buffalo之hello world