EXTJS与后台通信问题

calm_keep 2012-02-01 04:14:16
前台代码
var cm = new Ext.grid.ColumnModel( [ {
header : '编号',
dataIndex : 'id'
}, {
header : '用户名',
dataIndex : 'username',
width : 200
}, {
header : '角色',
dataIndex : 'role',
width : 200
} ]);
var data = [ [ '1', 'name1', 'desn1' ], [ '2', 'name1', 'desn1' ],
[ '3', 'name1', 'desn1' ], [ '4', 'name1', 'desn1' ],
[ '5', 'name1', 'desn1' ] ];

var create = Ext.data.Record.create([{
name : 'id',
mapping : 'id',
type : 'int'
},
{
name : 'username',
mapping : 'username',
type : 'string'
},
{
name : 'role',
mapping : 'role',
type : 'string'
}
]);

var ds=new Ext.data.Store({
remoteSort : true,
proxy:new Ext.data.HttpProxy({
url : 'userAction_getUsers.action',
method: 'POST'
}),
reader:new Ext.data.JsonReader({
root : 'users',
totalProperty : 'totalCount',
id : 'id'
},
// create
[{name : 'id', type : 'int'},
{name : 'username'},
{name : 'role'}]
),
successProperty: 'success'
});


var grid=new Ext.grid.GridPanel({
renderTo:Ext.getBody(),
store: ds,
width:800,
height:600,
cm:cm,
loadMask:{msg:'正在加载中,请稍后..'}
// bbar: new Ext.PagingToolbar({
// pageSize: 4,
// store: ds,
// displayInfo: true,
// beforePageText:"当前第",
// afterPageText:"页,共{0}页",
// lastText:"尾页",
// nextText :"下一页",
// prevText :"上一页",
// firstText :"首页",
// refreshText:"刷新页面",
// displayMsg: '显示第{0} 条到{1} 条记录,一共{2} 条',
// emptyMsg: "没有记录"
// }),
// tbar:[{text:"新增账号", handler:add_user},
// {text:"修改账号", handler:edit_user},
// {text:"删除账号", handler:del_user}]
});

grid.render();
ds.load({
// params:{start : 0,
// limit : 4}
// ,
callback:function(record,options,success)
{
if (success == false)
{
Ext.Msg.buttonText.ok = "确定";
Ext.Msg.alert("错误", "加载失败");
}
else
{
Ext.MessageBox.alert("提示", "success")
}
}
});

后台的action方法
public String getUsers() throws IOException {


List<User> list = userService.findAll();//这里的方法说明同上

JSONObject json = new JSONObject();
json.put("success", true);
JSONArray jsonObjects = new JSONArray();

int i=0;
Iterator<User> it = list.iterator();

while(it.hasNext()){
JSONObject jsonObject = new JSONObject();
User user = it.next();//这里的Users对象就不多说了,同上

jsonObject.put("id",user.getId());
jsonObject.put("username", user.getUserName());
jsonObject.put("role", user.getRole());

jsonObjects.add(i++, jsonObject);
}


json.put("totalCount", list.size());
json.put("users", jsonObjects);

outputResult(json.toString());


HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json; charset=GBK");
response.getWriter().write(json.toString());
response.getWriter().print(json.toString());

return null;


}

structs.xml的配置
<action name="userAction_getUsers" class="userAction" method="getUsers">
<result type="json">
<!-- <param name="root">users</param> -->
</result>
<result name="error">/login.jsp</result>
</action>


最后的结果在load的时候success返回 false,这个问题困扰我2天了,请各位大虾帮帮忙啊~~~
...全文
168 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧