具体的工程步骤:
首先,我们来搭建WEB服务端的程序:
这时,我们需要下载一个JAR。名为extdirect4j-0[1].3.1-source.jar,目前是最新版吧。因为这个包用到GG一些办法,那么,我们还需要下载gson-1.3.jar。
接下来,这些写一个继承ExtDirectRouter的类,如下面:
package com;
import ch.swissdotnet.extdirect4j.AnnotatedAction;
import ch.swissdotnet.extdirect4j.ExtDirectRouter;
import ch.swissdotnet.extdirect4j.ExtRemoteAction;
import ch.swissdotnet.extdirect4j.ExtRemoteMethod;
import ch.swissdotnet.extdirect4j.NamedAction;
public class MyExtDirectRouter extends ExtDirectRouter {
static public class Result {
private Long result;
private String msg;
public Result(Long result, String msg) {
this.result = result;
this.msg = msg;
}
}
static abstract public class AbstractAction {
abstract Long multy(long a, long b);
@ExtRemoteMethod(name = "multy1")
public Long multy(int a, long b) {
return -a * b;
}
}
@ExtRemoteAction(name = "Action", lazyInit = true)
static public class TestAction extends AbstractAction {
@ExtRemoteMethod
public Long multy(long a, long b) {
return a * b;
}
@ExtRemoteMethod(name = "multy2")
public Long multy(int a, long b) {
return a * b;
}
@ExtRemoteMethod
public Result multy(long a) {
return new Result(a * 2, "just a result");
}
@ExtRemoteMethod
public String sayHello(String value){
return "Hello, "+value;
}
@ExtRemoteMethod
public String getTree(String value){
System.out.println("被调到了");
return "[{"+
"'id':10,"+
"'leaf':false,"+
"'children':[{"+
"'id':11,"+
"'leaf':true,"+
"'children':null,"+
"'text':'S600'"+
"},{"+
"'id':12,"+
"'leaf':true,"+
"'children':null,"+
"'text':'SLK200'"+
"}],"+
"'text':'Benz'"+
"}]";
/*return "text:'Online',"+
"children:[{"+
"text:'Friends',"+
"expanded:true,"+
"children:[{"+
"text:'Jack',"+
"iconCls:'user',"+
"leaf:true"+
"}]"+
"}]";*/
}
}
@Override
protected void configureActions() {
this.addAction(new AnnotatedAction(TestAction.class)); //OK
//or so..
this.addAction(new AnnotatedAction("com.test.ExtdirectServlet$TestAction")); //OK
//or another else way in case we have not an access to action class in compile time
//but it is less scaled and has some restrictions
this.addAction(new NamedAction("com.test.ExtdirectServlet$TestAction")
.addMethod("multy", 1) // OK
.addMethod("multy", 2)); //error there is 2 methods called "multy" with 2 arguments;
}
}
测试:主要是测试我们自定义的类。因为ExtDirectRouter是一个继承了HttpServlet,那么MyExtDirectRouter 也算是一个Servlet。那么我们找到WEB文件,找出它的映射地址:比如
<servlet-mapping>
<servlet-name>MyExtDirectRouter</servlet-name>
<url-pattern>/remote/*</url-pattern>
</servlet-mapping>
我们用浏览器打开该Servlet看网页显示什么。如果是
Ext.app.MY_REMOTING_API = {"url":"remote/","type":"remoting","actions":{"Action":[{"name":"getTree","len":1},{"name":"multy","len":2},{"name":"multy","len":1},{"name":"multy2","len":2},{"name":"sayHello","len":1},{"name":"multy1","len":2}]}};
恭喜你,你已经成功啦
结尾:服务端到此为止。
补充服务端说明:在提交数据到客户端的时候,有可能遇到中文乱码问题,不怕,我们的MyExtDirectRouter是一个Servlet,在它的父类(ExtDirectRouter)里面,有doPost、doGet的办法,主要在这两个办法里面添加
response.setContentType("text/json; charset=utf-8");
- 大小: 51.4 KB
分享到:
相关推荐
最新ext3.0资源包最新ext3.0资源包最新ext3.0资源包最新ext3.0资源包最新ext3.0资源包最新ext3.0资源包最新ext3.0资源包
ext3.0ext3.0ext3.0ext3.0ext3.0ext3.0
Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档Ext 3.0 中文文档
ext 3.0 中文API ext 3.0 中文API ext 3.0 中文API ext 3.0 中文API ext 3.0 中文API
EXT3.0实现文件上传EXT3.0实现文件上传EXT3.0实现文件上传EXT3.0实现文件上传EXT3.0实现文件上传EXT3.0实现文件上传
Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文
EXT 入门实例,以一个简单的登录为例子、、、EXT3.0 登录实例,EXT3.0 源码
extjs3.0 ext3.0 ext文档 ext例子
Ext3.0使用示例
EXT3.0中文API
Myecplise 设置ext3.0自动提示功能 包含Spket的插件包和ext3.0的提示文件ext.jsb文件 ,以及具体设置操作
Ext3.0开发包
最新 发布 ext 3.0 中文 API 文档
ext3.0中的99%的控件的用法。包括表格。表单。分页工具栏。图标等。非常的详细。可以直接运行!
ext3.0包 +Skpet 在eclipse 自动提示 在这里分享啦, 如果不能下载或者不能使用 请留言
Ext3.0 api 帮助文档
Ext3.0发布RC1版本,API文档:http://extjs.com/deploy/ext-3.0-rc1/docs/
Ext 3.0 中文 API CHM 帮助 文档
Ext3.0中文文档详细介绍了Ext各个功能点的内容,包括常用的Store、Data、render、Grid、Form、Tree等。