jabsorb笔记_几个小例子第2/2页
更新时间:2008年10月11日 18:50:14 作者:
研究了一下 jabsorb,写了几个简单的例子,希望能够帮助菜鸟快速入门。
package com.test;
public class Test3{
public String p1;
public String p2;
public String p3;
public String getP1() {
return p1;
}
public void setP1(String p1) {
this.p1 = p1;
}
public String getP2() {
return p2;
}
public void setP2(String p2) {
this.p2 = p2;
}
public String getP3() {
return p3;
}
public void setP3(String p3) {
this.p3 = p3;
}
}
jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="JSONRPCBridge" scope="session" class="org.jabsorb.JSONRPCBridge" />
<jsp:useBean id="testJabsorb" scope="session" class="com.test.TestJabsorb" />
<%
JSONRPCBridge.registerObject("testJabsorb", testJabsorb);
%>
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/jsonrpc.js"></script>
<script>
jsonrpc = new JSONRpcClient("JSON-RPC")
//字符串参数
var result = jsonrpc.testJabsorb.getMessage('ray2')
document.write(result+'<br>')
//无参数
var result = jsonrpc.testJabsorb.getMessage()
document.write(result+'<br>')
//list参数
var result = jsonrpc.testJabsorb.getMessage({"javaClass":"java.util.ArrayList",'list':['h1','h2','h3']})
document.write(result+'<br>')
//数组参数
var result = jsonrpc.testJabsorb.getMessage(['h1','h2','h3'])
document.write(result+'<br>')
//bean参数
var result = jsonrpc.testJabsorb.getMessage({'javaClass':"com.test.Test3",p1:11,p2:22,p3:33})
document.write(result+'<br>')
//bean参数
var result = jsonrpc.testJabsorb.getMessage({'javaClass':"com.test.Test2",p1:1,p2:2})
document.write(result+'<br>')
//bean返回值
var res = jsonrpc.testJabsorb.getMessage2()
printProperty(res)
//bean返回值
var res = jsonrpc.testJabsorb.getMessage3()
printProperty(res)
//list返回值
var res = jsonrpc.testJabsorb.getList().list
printProperty(res)
//map返回值
var res = jsonrpc.testJabsorb.getMap().map
printProperty(res)
function printProperty(ele){
for(var p in ele){
document.write(p+':'+ele[p]+',')
}
document.write('<br>')
}
//异步调用
function callback(result,exception){
if(exception==null){
//alert(result)
}
}
var result = jsonrpc.testJabsorb.getMessage(callback,'ray2')
</script>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>JSONRPCServlet</servlet-name>
<servlet-class>org.jabsorb.JSONRPCServlet</servlet-class>
<init-param>
<param-name>gzip_threshold</param-name>
<param-value>0</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JSONRPCServlet</servlet-name>
<url-pattern>/JSON-RPC</url-pattern>
</servlet-mapping>
</web-app>
相关文章
javascript 单例模式演示代码 javascript面向对象编程
单例模式的好处就是:类只实例化一次,省资源,节省开销,提高速度,学习js面向对象编程的朋友可以参考下。2010-04-04JavaScript的单例模式 (singleton in Javascript)
JavaScript的单例模式 (singleton in Javascript)2010-06-06
最新评论