花了不少时间 终于解决了缺包、冲突包、错误包等jar包问题
直接访问UserAction.action也能得到一个有json数据的文件
但是用datagrid的属性url 却还是无法得到数据 求这方面大虾能帮忙看看我的代码还有什么错误。
package com.testDWR.service;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;import com.opensymphony.xwork2.ActionSupport;
import com.testDWR.model.User;public class UserAction extends ActionSupport { List<Object> rowsList = new ArrayList<Object>();
int total = 100;
public int getTotal() {
return total;
} public void setTotal(int total) {
this.total = total;
} public String execute() {
for (int i = 0; i < 10; i++) {
User user = new User();
user.setUserId(i);
user.setUserName("user_"+i);
user.setPassword("pass_"+i);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("userId", user.getUserId());
map.put("userName", user.getUserName());
map.put("password", user.getPassword());
rowsList.add(map);
}
return SUCCESS;
} public List<Object> getRowsList() {
return rowsList;
} public void setRowsList(List<Object> rowsList) {
this.rowsList = rowsList;
}
}
<?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">
<struts>
<constant name="struts.action.extension" value="action"></constant>
<constant name="struts.devMode" value="true"></constant>
<package name="user" extends="json-default">
<action name="UserAction" class="com.testDWR.service.UserAction">
<result type="json"></result>
</action>
</package>
</struts>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'jqueryui.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="js/engine.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="dwr/interface/service.js"></script>
<link rel="stylesheet" type="text/css" href="jqueryui/themes/default/easyui.css">
<script type="text/javascript" src="jqueryui/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jqueryui/jquery.easyui.min.js"></script>
<script type="text/javascript">
function showUserList() {
alert('进来了');
$('#table').datagrid({
title:'Column Group',
iconCls:'icon-save',
width:560,
height:250,
url:'UserAction.action',
columns:[[
{field:'userId',title:'用户ID'},
{field:'userName',title:'用户名'},
{field:'password',title:'密码'}
]],
pagination:true
});
}
</script>
</head>
<body>
<table id="table">
</table>
<a href="javascript:showUserList()">得到用户组</a>
</body>
</html>
直接访问UserAction.action也能得到一个有json数据的文件
但是用datagrid的属性url 却还是无法得到数据 求这方面大虾能帮忙看看我的代码还有什么错误。
package com.testDWR.service;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;import com.opensymphony.xwork2.ActionSupport;
import com.testDWR.model.User;public class UserAction extends ActionSupport { List<Object> rowsList = new ArrayList<Object>();
int total = 100;
public int getTotal() {
return total;
} public void setTotal(int total) {
this.total = total;
} public String execute() {
for (int i = 0; i < 10; i++) {
User user = new User();
user.setUserId(i);
user.setUserName("user_"+i);
user.setPassword("pass_"+i);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("userId", user.getUserId());
map.put("userName", user.getUserName());
map.put("password", user.getPassword());
rowsList.add(map);
}
return SUCCESS;
} public List<Object> getRowsList() {
return rowsList;
} public void setRowsList(List<Object> rowsList) {
this.rowsList = rowsList;
}
}
<?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">
<struts>
<constant name="struts.action.extension" value="action"></constant>
<constant name="struts.devMode" value="true"></constant>
<package name="user" extends="json-default">
<action name="UserAction" class="com.testDWR.service.UserAction">
<result type="json"></result>
</action>
</package>
</struts>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'jqueryui.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="js/engine.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="dwr/interface/service.js"></script>
<link rel="stylesheet" type="text/css" href="jqueryui/themes/default/easyui.css">
<script type="text/javascript" src="jqueryui/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jqueryui/jquery.easyui.min.js"></script>
<script type="text/javascript">
function showUserList() {
alert('进来了');
$('#table').datagrid({
title:'Column Group',
iconCls:'icon-save',
width:560,
height:250,
url:'UserAction.action',
columns:[[
{field:'userId',title:'用户ID'},
{field:'userName',title:'用户名'},
{field:'password',title:'密码'}
]],
pagination:true
});
}
</script>
</head>
<body>
<table id="table">
</table>
<a href="javascript:showUserList()">得到用户组</a>
</body>
</html>
将easyui.css和icon.css两个CSS文件引用进来就OK了(jquery-easyui-1.2.4.zip里面有),折腾了半天。
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/easyui.css">
<link rel="stylesheet" type="text/css" href="css/icon.css">
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript">
function showUserList() {
alert('进来了');
$('#table').datagrid({
url:'userAction.action',
columns:[[
{field:'userId',title:'ID',width:100},
{field:'userName',title:'用户名',width:100},
{field:'password',title:'密码',width:100,align:'right'}
]]
});
}
</script>
</head>
<body>
<div>
<a href="javascript:showUserList()">得到用户组</a>
</div>
<hr>
<div>
<table id="table">
</table>
</div>
</body>
</html>
https://cwiki.apache.org/confluence/display/WW/JSON%20Plugin
http://www.jeasyui.com/documentation/datagrid.php
http://jqueryui.com/download
火狐报错
错误: _d1 is undefined
源文件:http://localhost:8081/testDWR/jqueryui/jquery.easyui.min.js
行:892
火狐报错
错误: _d1 is undefined
源文件:http://localhost:8081/testDWR/jqueryui/jquery.easyui.min.js
行:892
不能用rowsList 一定要改名rows
不知道怎么回事 不然火狐报错 rows undefined
我只能说jqueryui datagrid这个插件有病
LZ说的对 private List<Object> rows = new ArrayList<Object>();//rows固定命名
private int total;//总条数
需要的jar包就是struts2必须的jar以及struts2-json-plugin.jar;JS和CSS方面
<link rel="stylesheet" type="text/css" href="css/easyui.css">
<link rel="stylesheet" type="text/css" href="css/icon.css">
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>