【转】buffalo-demo(4)--返回对象

 

页面代码
doc.simple4.jsp
<%@ page contentType="text/html;charset=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>返回对象</title>
<script language="JavaScript" src="js/prototype.js"></script>
<script language="JavaScript" src="js/buffalo.js"></script>

<script language="javascript">
var endPoint="<%=request.getContextPath()%>/BUFFALO";

function cmdRandomUser() {
var buffalo = new Buffalo(endPoint);
buffalo.remoteCall("simpleService.randomUser",[buffalo:], function(reply) {
  var obj = reply.getResult();
  Buffalo.getElementById("user_id").value=obj.id;

  Buffalo.getElementById("user_name").value=obj.name;
  Buffalo.getElementById("user_age").value=obj.age;
  Buffalo.getElementById("user_sex").value=obj.sex;
  Buffalo.getElementById("user_memo").value=obj.memo;
});
}
</script>
<input name="Submit5" type="button" onClick="cmdRandomUser()" value="随机用户">
<p>用户对象包括编号,姓名,年龄,性别,简介。</p>
<table border="1" bordercolor="#006600">
  <tr>
    <td>编号(1,2,3可用)</td>
    <td><input name="user_id" type="text" id="user_id">    </td>
  </tr>
  <tr>
    <td>姓名</td>
    <td><input name="user_name" type="text" id="user_name"></td>
  </tr>
  <tr>
    <td>年龄</td>
    <td><input name="user_age" type="text" id="user_age"></td>
  </tr>
  <tr>
    <td>性别</td>
    <td><input name="user_sex" type="text" id="user_sex"></td>
  </tr>
  <tr>
    <td>简介</td>
    <td><textarea name="user_memo" rows="4" wrap="VIRTUAL" id="user_memo"></textarea></td>
  </tr>
</table>
</html>
服务器端代码
SimpleService.java
package net.buffalo.demo.simple;

public class SimpleService {

private static User[] users = {
  new User(1,"张三丰", 90, true"武当派开派祖师"),
  new User(2,"令狐冲", 30, true"华山派弟子"),
  new User(3,"乔峰", 36, true"身份复杂,曾为丐帮帮主,后自杀"),
  new User(4,"赵灵儿", 16, false"女娲后人"),
  new User(5,"苏蓉蓉", 24, false"楚留香红颜知己之一,熟知天文地理各种知识"),
};

public User randomUser() {
  try {
   Thread.sleep(1000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  int r = new Random().nextInt(5);
  return users[r];
}
}
属性文件
buffalo-service.properties
# simpleService, The simple Service
simpleService=net.buffalo.demo.simple.SimpleService

 

你可能感兴趣的:(demo)