easyui+struts2:datagrid无法不能得到数据

转自:https://bbs.csdn.net/topics/390980437

easyui+struts2:datagrid无法访问到指定action:

userlist.jsp部分代码:

XML/HTML code
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
     < 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配置:

XML/HTML code
 
?
1
2
3
4
5
6
7
8
9
10
     
< 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代码:

Java code
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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,返回结果:

XML/HTML code
 
?
1
{"Rows":[{"name":"管理员","user":"admin"},{"name":"李四","user":"ls"}]}


项目添加的包如下图:

 
 
 
 
 
 
 
 
 
 
 
 
Bbs1
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值