[求助]easyui+struts2:datagrid无法访问到指定action,不能得到数据

不应挽留 2015-01-30 11:48:52
easyui+struts2:datagrid无法访问到指定action:

userlist.jsp部分代码:
	<script type="text/javascript" src="libs/easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="libs/easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="libs/easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css" href="libs/easyui-1.3.5/themes/default/easyui.css" >
<link rel="stylesheet" type="text/css" href="libs/easyui-1.3.5/themes/icon.css">

<script type="text/javascript">
$(function() {
$('#mydatagrid').datagrid({
title : '用户管理',
iconCls : 'icon-ok',
width : 600,
pageSize : 5,//默认选择的分页是每页5行数据
pageList : [ 5, 10, 15, 20 ],//可以选择的分页集合
nowrap : true,//设置为true,当数据长度超出列宽时将会自动截取
striped : true,//设置为true将交替显示行背景。
collapsible : true,//显示可折叠按钮
toolbar:"#tb",//在添加 增添、删除、修改操作的按钮要用到这个
url:'userList.action',//url调用Action方法
loadMsg : '数据装载中......',
singleSelect:true,//为true时只能选择单行
fitColumns:true,//允许表格自动缩放,以适应父容器
//sortName : 'xh',//当数据表格初始化时以哪一列来排序
//sortOrder : 'desc',//定义排序顺序,可以是'asc'或者'desc'(正序或者倒序)。
remoteSort : false,
frozenColumns : [ [ {
field : 'user',
checkbox : true
} ] ],
pagination : true,//分页
rownumbers : true//行数
});

});

</script>

</head>
<body>


<table id="mydatagrid">

<thead>
<tr>

<th data-options="field:'user',width:100,align:'center'">用户名</th>
<th data-options="field:'name',width:100,align:'center'">姓名</th>

</tr>
</thead>

</table>

</body>
</html>


struts.xml配置:
	
<package name="struts2" extends="json-default">

<action name="userList" class="com.xforce.login.action.UserListAction" method="getUsers">
<result type="json" >
<param name="root">rows</param>
</result>
</action>

</package>


UserListAction.java代码:
package com.xforce.login.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.hibernate.engine.spi.RowSelection;

import com.opensymphony.xwork2.ActionSupport;
import com.xforce.login.dao.impl.UserDaoImpl;
import com.xforce.login.entity.User;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import com.xforce.login.entity.User;
import com.xforce.login.dao.UserDao;
import com.xforce.login.dao.impl.UserDaoImpl;

public class UserListAction extends ActionSupport {

private JSONObject rows = new JSONObject();

public String getUsers() throws Exception{
UserDaoImpl udi = new UserDaoImpl();
List<User> users = udi.listUser();
HashMap<String, Object> maps = new HashMap<String, Object>();
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
for (User user :users) {
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("name",user.getName());
hashMap.put("user",user.getUser());
list.add(hashMap);
}
maps.put("Rows", list);
//rows = JSONObject.parseObject(JSON.toJSONString(maps));
rows = JSONObject.fromObject(maps);
System.out.println(rows);
return SUCCESS;
}

public JSONObject getRows() {
return rows ;
}

public void setRows(JSONObject rows) {
this.rows = rows;
}

}


调试时无法显示数据,在UserListAction中设置断点,发现未进入,(JSP页面利用LigerUI可正常访问UserListAction返回json显示数据),chrome调试审查元素,network中显示如下图:

不能访问http://localhost:8080/FixOnline/userList.action
但在地址栏中输入该url,返回结果:
{"Rows":[{"name":"管理员","user":"admin"},{"name":"李四","user":"ls"}]}

项目添加的包如下图:


困扰,求助,多谢!
...全文
544 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
鬼扯三国 2017-04-19
  • 打赏
  • 举报
回复
我是请求都没有发到后台啊 ,用地址都能请求到数据 ,大神求指点
3.14 2017-02-24
  • 打赏
  • 举报
回复
map.put("total", xdzbtList.size()); map.put("rows", xdzbtList); 少了一句
不应挽留 2016-03-21
  • 打赏
  • 举报
回复
引用 10 楼 H352296390 的回复:
你好,能问下,一开始访问不到action是怎么回事吗,我都搞了三天没找到原因,急死了
开始访问到了action,但json格式不对,所以datagrid无法显示数据
H352296390 2015-06-08
  • 打赏
  • 举报
回复
你好,能问下,一开始访问不到action是怎么回事吗,我都搞了三天没找到原因,急死了
不应挽留 2015-02-01
  • 打赏
  • 举报
回复
发现还是跟json的格式有关,action中
rows = JSONObject.fromObject(maps);
替换为
rows = JSONObject.fromObject("{\"rows\":[{\"isLeaf\":0,\"nodeAction\":\"\",\"nodeID\":1,\"nodeIcon\":\"icon-sys\",\"nodeText\":\"系统管理\",\"parenetID\":0},{\"isLeaf\":1,\"nodeAction\":\"sys/entryM.html\",\"nodeID\":2,\"nodeIcon\":\"icon-nav\",\"nodeText\":\"栏目管理\",\"parenetID\":1}],\"total\":2}");
可以展现测试数据...
不应挽留 2015-02-01
  • 打赏
  • 举报
回复
已解决,原来easyui中datagrid绑定json中必须为rows,
maps.put("Rows", list);
改为小写的rows即可显示数据了...
wyx100 2015-02-01
  • 打赏
  • 举报
回复
mould_self 2015-01-31
  • 打赏
  • 举报
回复
jquery和easyUI 的文件引入路径错了,所以easyUI的代码无法识别。如果你的libs是webapp根目录下的在前面加个’/‘就可以了 如果不是可以用${request.contextPath}来获取项目路径 如果大量页面需要引用的话就用<c:set scope="application" var="path" value="<%=request.getContextPath()%>"></c:set>,以后只要用${path}就能代替${request.contextPath}
不应挽留 2015-01-31
  • 打赏
  • 举报
回复
引用 5 楼 lixiang584 的回复:
为了方便大侠们定位问题,我把项目上传了,若有时间麻烦帮忙调试一下。谢了! 数据库:mysql,项目目录中包含数据库fixonline.sql文件。 测试页面http://localhost:8080/userlist1.jsp页面功能即可。 下载地址:http://download.csdn.net/detail/aiolox/8412979 (由于连续回帖数不能超过3,换账号留言。)
不好意思,资源未通过审核...
lixiang584 2015-01-31
  • 打赏
  • 举报
回复
为了方便大侠们定位问题,我把项目上传了,若有时间麻烦帮忙调试一下。谢了! 数据库:mysql,项目目录中包含数据库fixonline.sql文件。 测试页面http://localhost:8080/userlist1.jsp页面功能即可。 下载地址:http://download.csdn.net/detail/aiolox/8412979 (由于连续回帖数不能超过3,换账号留言。)
不应挽留 2015-01-31
  • 打赏
  • 举报
回复
另外若哪位能提供easyui+struts2+hibernate或是LigerUI+struts2+hibernate包含layout与datagrid增删改查较好的示例demo框架同是万分感激!
不应挽留 2015-01-31
  • 打赏
  • 举报
回复
补充一张在页面中<table>标签加入class="easyui-datagrid"属性后的调试图:
不应挽留 2015-01-31
  • 打赏
  • 举报
回复
引用 1 楼 beautiful_life12 的回复:
jquery和easyUI 的文件引入路径错了,所以easyUI的代码无法识别。如果你的libs是webapp根目录下的在前面加个’/‘就可以了
如果不是可以用${request.contextPath}来获取项目路径
如果大量页面需要引用的话就用<c:set scope="application" var="path" value="<%=request.getContextPath()%>"></c:set>,以后只要用${path}就能代替${request.contextPath}

感谢,应该不是路径问题,easyui的界面显示正常,请看倒数第2张图。
另外在页面中<table>标签加入class属性:
<table id="mydatagrid" class="easyui-datagrid">

可以访问到userList.action了,但界面仍不能显示数据。
下图是chrome审查元素中的network:

81,094

社区成员

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

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