求完整的代码:
用java将查询的列表封装成json传递到前台,前台获取json格式的数据
这边的url该怎么写
<!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=UTF-8">
<title>Complex DataGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../themes/icon.css">
<link rel="stylesheet" type="text/css" href="demo.css">
<script type="text/javascript" src="../jquery-1.6.min.js"></script>
<script type="text/javascript" src="../jquery.easyui.min.js"></script>
<script>
$(function(){
$('#test').datagrid({
title:'My DataGrid',
iconCls:'icon-save',
width:700,
height:350,
nowrap: false,
striped: true,
collapsible:true,
url:'datagrid_data.json', sortName: 'code',
sortOrder: 'desc',
remoteSort: false,
idField:'code',
frozenColumns:[[
{field:'ck',checkbox:true},
{title:'code',field:'code',width:80,sortable:true}
]],
columns:[[
{title:'Base Information',colspan:3},
{field:'opt',title:'Operation',width:100,align:'center', rowspan:2,
formatter:function(value,rec){
return '<span style="color:red">Edit Delete</span>';
}
}
],[
{field:'name',title:'Name',width:120},
{field:'addr',title:'Address',width:220,rowspan:2,sortable:true,
sorter:function(a,b){
return (a>b?1:-1);
}
},
{field:'col4',title:'Col41',width:150,rowspan:2}
]],
pagination:true,
rownumbers:true,
toolbar:[{
id:'btnadd',
text:'Add',
iconCls:'icon-add',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('add')
}
},{
id:'btncut',
text:'Cut',
iconCls:'icon-cut',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('cut')
}
},'-',{
id:'btnsave',
text:'Save',
disabled:true,
iconCls:'icon-save',
handler:function(){
$('#btnsave').linkbutton('disable');
alert('save')
}
}]
});
var p = $('#test').datagrid('getPager');
$(p).pagination({
onBeforeRefresh:function(){
alert('before refresh');
}
});
});
</script>
</head>
<body>
<table id="test"></table>
</body>
</html>
用java将查询的列表封装成json传递到前台,前台获取json格式的数据
这边的url该怎么写
<!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=UTF-8">
<title>Complex DataGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../themes/icon.css">
<link rel="stylesheet" type="text/css" href="demo.css">
<script type="text/javascript" src="../jquery-1.6.min.js"></script>
<script type="text/javascript" src="../jquery.easyui.min.js"></script>
<script>
$(function(){
$('#test').datagrid({
title:'My DataGrid',
iconCls:'icon-save',
width:700,
height:350,
nowrap: false,
striped: true,
collapsible:true,
url:'datagrid_data.json', sortName: 'code',
sortOrder: 'desc',
remoteSort: false,
idField:'code',
frozenColumns:[[
{field:'ck',checkbox:true},
{title:'code',field:'code',width:80,sortable:true}
]],
columns:[[
{title:'Base Information',colspan:3},
{field:'opt',title:'Operation',width:100,align:'center', rowspan:2,
formatter:function(value,rec){
return '<span style="color:red">Edit Delete</span>';
}
}
],[
{field:'name',title:'Name',width:120},
{field:'addr',title:'Address',width:220,rowspan:2,sortable:true,
sorter:function(a,b){
return (a>b?1:-1);
}
},
{field:'col4',title:'Col41',width:150,rowspan:2}
]],
pagination:true,
rownumbers:true,
toolbar:[{
id:'btnadd',
text:'Add',
iconCls:'icon-add',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('add')
}
},{
id:'btncut',
text:'Cut',
iconCls:'icon-cut',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('cut')
}
},'-',{
id:'btnsave',
text:'Save',
disabled:true,
iconCls:'icon-save',
handler:function(){
$('#btnsave').linkbutton('disable');
alert('save')
}
}]
});
var p = $('#test').datagrid('getPager');
$(p).pagination({
onBeforeRefresh:function(){
alert('before refresh');
}
});
});
</script>
</head>
<body>
<table id="test"></table>
</body>
</html>
解决方案 »
- java 如何调用c# .dll文件
- MyEclipse哪个版本稳定~~
- 严禁未登录用户访问页面用java实现除了session外还有别的方法吗
- j2ee权限控制
- tomcat怎么为两个不同的j2ee项目配置单独的log文件?
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断
- spring hibernate整合出现错误
- 最近有个项目要求能够像百度那样,在上次查询结果中继续查询,特来请教,谢谢
- 数据库抛出的:org.postgresql.util.PSQLException: Operation requires a scrollable ResultSet, but this ResultSet is FORWARD_ONLY.
- JDBC问题
- 请高手指教,Web问题
- 哪位大侠可以介绍一下J2EE和J2SE有什么大的区别?
List list = new ArrayList();
list.add( "first" );
list.add( "second" );
JSONArray jsonArray2 = JSONArray.fromObject( list );
2. Map集合转换成json代码
Map map = new HashMap();
map.put("name", "json");
map.put("bool", Boolean.TRUE);
map.put("int", new Integer(1));
map.put("arr", new String[] { "a", "b" });
map.put("func", "function(i){ return this.arr[i]; }");
JSONObject json = JSONObject.fromObject(map);
3. Bean转换成json代码
JSONObject jsonObject = JSONObject.fromObject(new JsonBean());
4. 数组转换成json代码
boolean[] boolArray = new boolean[] { true, false, true };
JSONArray jsonArray1 = JSONArray.fromObject(boolArray);
5. 一般数据转换成json代码
JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']" );
getResponse().getWriter().write(jsonObject.toString());当把数据转为json后,用如上的方法发送到客户端。前端就可以取得json数据了。
前端通过什么方法获取json格式的数据呢?
List<WsRechargeInfoVO> wsList=getWsRechargeInfoList(rechargeList);
if(wsList!=null && wsList.size()>0){
for(WsRechargeInfoVO ws:wsList){
JSONObject json=new JSONObject(ws);
result+="<rechargeInfo>";
result+=XML.toString(json);
result+="</rechargeInfo>";
}
}上面是我写的一段从数据库查出的内容转json的数据,你可以将你需要转的属性定义到一个vo里,然后调用我上面的方法就可以生成一段json格式的字符串了,如果还要将这段json字符串格式化的话可以执行下面代码try {
result=Dom4jUtil.formatXml(result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}Dom4jUtil.java/**
* 将XML字符串格式化
* @param str
* @return
* @throws Exception
*/
public static String formatXml(String str) throws Exception {
Document document = null;
document = DocumentHelper.parseText(str);
// 格式化输出格式
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
StringWriter writer = new StringWriter();
// 格式化输出流
XMLWriter xmlWriter = new XMLWriter(writer, format);
// 将document写入到输出流
xmlWriter.write(document);
xmlWriter.close(); return writer.toString();
}
是通过af.getHttpResponse().getWriter().write(array.toString());传送
还是af.getHttpRequest().setAttribute("person", array.toString());传送然后jsp的jquery的url是怎么写的
$('#test').datagrid({
url:'',})
$(function(){
$('#test').datagrid({
....
url:'test.action',
.....
});
});
在struts.xml中加入
class="action.test" action是包名,test是类 <package name="user_json" extends="json-default">
<action name="test" class="action.test">
<result type="json">
<param name="root">test_Json</param>
</result>
</action>
</package>
在test.java中 JSONObject jsonobj = new JSONObject();
List userlist = nlist.queryByPage(start, number); //用户全部信息
jsonobj.put("total", all);//每页信息总数
jsonobj.put("rows", userlist);//每页信息内容
test_Json = JSONObject.fromObject(jsonobj);