Help!!! Struts2+ExtJs action返回结果输出到其他页面的问题

想要实现的是获取action返回后跳转到另外的页面(struts.xml控制),并把数据用GridPane输出.也就是用gridpanel替换掉""标签的作用.
例如 getUser.jsp->submit->searchuser.action->(json string)userlist->userlist.jsp(gridpanel显示).
请问,ExtJs是AJAX 实现的话,[color=red]action是否一定是将数据返回到提交页面的?[/color]例如 getUser.jsp->searchuser.action->getUser.jsp.
如果是,那应该怎样将数据转移给我想要跳转的页面(userlist.jsp)?
下面是我做的一个例子,跳转到userlist.jsp后GridPanel[color=red]只看到Grid而没有数据[/color],初学ExtJs,请各位多多指教!!

getUser.jsp(action="searchuser")用于提交用户ID,略过.

struts.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">


method="searchUser">
/userlist.jsp



[/code]

响应searchuser.action的class:userAction

[code="java"]
package com.prodinfo.action;

import java.util.Map;
import java.util.List;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Collection;
import com.prodinfo.biz.*;
import com.prodinfo.common.*;
import com.prodinfo.dao.*;
import com.prodinfo.pojo.Logger;
import com.prodinfo.pojo.SysUsr;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;

public class UserAction extends ActionSupport {

private String userid;
private String password;
private String username;
private String usrpwdques;
private String usrpwdans;
private String usremail;
private ILoggerDao loggerdao;
private IUserOperation uo;
private ComDate comdate;
private ComSession ssn;
private SysUsr sysusr;

public String userlist;

public UserAction() {
    comdate = new ComDate();
    ssn = new ComSession();
}
public String getUserid() {
    return userid;
}
public void setUserid(String userid) {
    this.userid = userid;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getUsrpwdques() {
    return usrpwdques;
}
public void setUsrpwdques(String usrpwdques) {
    this.usrpwdques = usrpwdques;
}
public String getUsrpwdans() {
    return usrpwdans;
}
public void setUsrpwdans(String usrpwdans) {
    this.usrpwdans = usrpwdans;
}
public String getUsremail() {
    return usremail;
}
public void setUsremail(String usremail) {
    this.usremail = usremail;
}
public void setLoggerdao(ILoggerDao loggerdao) {
    this.loggerdao = loggerdao;
}
public void setUo(IUserOperation uo) {
    this.uo = uo;
}
public String getUserlist() {
    return userlist;
}
public void setUserlist(String userlist) {
    this.userlist = userlist;
}
public String searchUser() {
    try {
        ComUserInfo comuserinfo = new ComUserInfo();
        if (comuserinfo.getUserid() != "") {
            List result = uo.searchUser(getUserid());
            JsonUtil ju = new JsonUtil();
            String jsresult = ju.collection2json(result);
            this.userlist = ("{" + "\"userlist\": " + jsresult + " }");
            System.out.println(userlist);
            //response.getWriter().println(userlist);
            return SUCCESS;
        } else {
            ssn.add("errmsg", "User not login yet!");
            return ERROR;
        }
    } catch (Exception e) {
        ssn.add("errmsg", e.getMessage());
        return ERROR;
    }
}

}
[/code]

userAction返回的"userlist"数据如下:

{
"userlist": [
{"usrCreateBy":"","usrCreateDate":"","usrDisableDate":"",
"usrEmail":"Frankie@together.com","usrId":"80319474","usrName":"Frankie",
"usrPwd":"1233","usrPwdAns":"1+1","usrPwdQues":"2",
"usrRemark":"","usrUpdateBy":"","usrUpdateDate":""},

{"usrCreateBy":"","usrCreateDate":"","usrDisableDate":"",
"usrEmail":"Justin@together.com","usrId":"80334272","usrName":"Justin",
"usrPwd":"1234","usrPwdAns":"2","usrPwdQues":"1+1",
"usrRemark":"nothing","usrUpdateBy":"","usrUpdateDate":""},

{"usrCreateBy":"","usrCreateDate":"","usrDisableDate":"",
"usrEmail":"Justin@together.com","usrId":"sa","usrName":"sysadmin",
"usrPwd":"a","usrPwdAns":"2","usrPwdQues":"1+1",
"usrRemark":"nothing","usrUpdateBy":"","usrUpdateDate":""}
]
}

输出页面的js:
userlist.js:
[code="java"]
/*

Ext.onReady(function() {
Ext.QuickTips.init();

// turn on validation errors beside the field globally
// Ext.form.Field.prototype.msgTarget = 'side';
var cm = new Ext.grid.ColumnModel([{
    header : '用户ID',
    dataIndex : 'userId'
}, {
    header : '用户昵称',
    dataIndex : 'usrName'
}, {
    header : '密码',
    dataIndex : 'usrPwd'
}, {
    header : '电子邮件地址',
    dataIndex : 'usrEmail'
}, {
    header : '密码提示问题',
    dataIndex : 'usrPwdQues'
}, {
    header : '密码提示问题答案',
    dataIndex : 'usrPwdAns'
}]);

var reader = new Ext.data.Store({
    root : 'userlist'
}, [{
    name : 'usrId',
    mapping : 'userId'
}, {
    name : 'usrName',
    mapping : 'usrName'
}, {
    name : 'usrPwd',
    mapping : 'usrPwd'
}, {
    name : 'usrEmail',
    mapping : 'usrEmail'
}, {
    name : 'usrPwdQues',
    mapping : 'usrPwdQues'
}, {
    name : 'usrPwdAns',
    mapping : 'usrPwdAns'
}]);

var pxy = new Ext.data.HttpProxy({
    url : 'searchuser.action',
    method : 'GET'
})

var ds = new Ext.data.JsonStore({
    proxy : pxy,
    reader : reader
});

var grid = new Ext.grid.GridPanel({
    store : ds,
    sm : sm,
    cm : cm,
    loadMask : {
        msg : ' 数据加载中...'
    },
    autoHeight : true
});

var sm = new Ext.grid.CheckboxSelectionModel();

var vp = new Ext.Viewport({
    layout : "border",
    frame : true,
    title : "注册",
    autoHeight : true,
    items : [{// Viewport
        region : "north",
        height : 100,
        title : "顶部面板"
    }, {
        region : "south",
        height : 50,
        title : "底部面板"
    }, {
        region : "west",
        width : "20%",
        title : "左边面板"
    }, {
        region : "east",
        width : "20%",
        title : "右边面板"
    }, {
        region : "center",
        title : "中央面板",
        items : [frm = new Ext.FormPanel({
            items : [grid]
        }       /* Eof formpanel */)
        /* Eof border center */]
    }       /* Eof Viewport */]
});
grid.render();
ds.load();
vp.render(document.body);

});

[/code]

[b]问题补充:[/b]
感谢 yourgame (资深架构师) 的回答

你完全理解错误了..

如果用到了extjs 就不需要什么跳转了.你直接输出out.print(json);

您的意思是否我在问题里提到的"ExtJs是AJAX 实现的话,action是否一定是将数据返回到提交页面的?例如 getUser.jsp->searchuser.action->getUser.jsp."?
可是如果我想把数据放到其他页面的话,我应该怎么做才能把数据送过去呢.请不吝赐教.
[b]问题补充:[/b]

感谢两位的回答,我现在转换了思路,当用户提交了之后,先进行页面跳转到userlist.jsp,然后才在userlist,jsp里去请求action的返回数据,并放到GridPanel里,不知道这种思路是否可行.
即:

getUser.jsp->Submit->redirect->userlist.jsp->searchuser.action->userlist.jsp(Grid展现)

3个回答

有种办法,你在Action中将json格式的数据放到一个变量里,然后你转发到

.jsp

这个jsp就页面里这么写

然后你在写个请求的action,负责取数据的就可以了。只不过就是把action中负责装json格式的变量统一转发到一个页面。

你完全理解错误了..

如果用到了extjs 就不需要什么跳转了.你直接输出out.print(json);

还有一点,竟然你用了struts2,就没有必要去用json-lib.jar struts2自带的插件扩展好强大.而且又很方便
下面是我用extjs+ struts2整合的两个例子
[url]http://yourgame.iteye.com/blog/353361[/url]
[url]http://yourgame.iteye.com/blog/252853[/url]

对啊,我说的意思就是你所理解的思路。基本上差不多,我现在的项目就是用这种方式来做的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐