1、dwr如何处理返回值
java代码
public class Test1 {
public String hello(){
return "世界,你好!";}}
调用代码
function test1(){ T1.hello( function(data){ alert(data); });}
2、如何传递参数
java代码
public class Test2 {
public String hello(String name,int age){
return "你好,你的姓名是【"+name+"】,年龄是【"+age+"】";
}}
调用代码
function test1(){
T2.hello( "张三", 18 ,function(data){alert(data);} );}
3、处理返回值为List情况
java代码
public class Test4 {
public List hello(){
List rtn=new ArrayList();rtn.add("世界");rtn.add("你好");return rtn; }}
调用代码
function test1(){ T4.hello( function(datas){ for(var i=0;i<datas.length;i++){ alert(datas[i]); }})}
4、处理返回值为Map类型的情况
java代码
public class Test5 {
public Map hello(){
Map map=new HashMap();map.put("k1","世界");map.put("k2", "你好"); return map; }}
调用代码
function test2(){
T5.hello(
function(datas){
for(var prop in datas){
alert("key= "+prop+",value= " + datas[prop]);
}});}
5、处理返回值为二维数组的情况
java代码
public class Test6 {
public List hello(){
List rtn =new ArrayList();
rtn.add(new String[]{"Value1","Value2"});
rtn.add(new String[]{"V1","V2","V3","V4"});
return rtn;
}
}
调用代码
function test1(){
T6.hello(
function(datas){
for(var i=0;i<datas.length;i++){
for(var j=0;j<datas[i].length;j++){
alert(datas[i][j]);}}});}
6、 怎样设置为同步
dwr.engine.setAsync(true);