Servlet中的List:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ext e = new ext();
List<User> l = e.page2(0, 3);
JSONArray jsonArray = Test3.getListjsonArray(l);
response.setContentType("text/json;charset=UTF-8");// 设置数据到前台显示的字符编码,如果不转会有乱码
response.getWriter().print(jsonArray);
System.out.println(jsonArray);
} 怎样让他显示在jsp页面? 急求大哥大姐些帮助啊!!!
前台Grid都有store 里边定义了固定的数据格式 你的后台应该返回相应的格式
好好利用搜索引擎吧~~
后台返回
String result = JSONArray.fromObject(jsonArray ).toString();
//String str = "{totalProperty:" + size + ",data:"
+ JSONArray.fromObject(list).toString() + "}"; //用于分页
response.getWriter().print(result );var store = new Ext.data.JsonStore({
url:url,
//root:'data',//注释两行用于分页的
//totalProperty:"totalProperty",
fields:fields,
pruneModifieRecords:true //store每次提交后自动清除modified标记
});
store.load();
基本上就这样了。
我写成这样了。。但是还是不行?、 还请帮忙看哈public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ext e = new ext();
List<User> l = e.page2(0, 3);
JSONArray jsonArray = Test3.getListjsonArray(l);
String result = JSONArray.fromObject(jsonArray ).toString();
response.setContentType("text/json;charset=UTF-8");// 设置数据到前台显示的字符编码,如果不转会有乱码
response.getWriter().print(result);
System.out.println(result);
}前台
<script type="text/javascript">
Ext.onReady(function() {
var store = new Ext.data.JsonStore( {
url:"extjsController",
root:"result",
fileds:['id','name','sex'],
pruneModifieRecords:true
});
store.load();
var grid = new Ext.grid.GridPanel( {
renderTo : "hello",
title : "json列表",
height : 150,
width : 600,
columns : [ {
header : "编号",
dataIndex : "id"
}, {
header : "姓名",
dataIndex : "name"
}, {
header : "性别",
dataIndex : "sex"
} ],
store : store,
autoExpandColumn : 2
});
});
</script>
</head>
<body>
<div id="hello" align="center">
midjhfuird
</div>
</body>
结果只有显示这个表格没有数据库中读取出来的内容
没有发现你的servlet请求前面有斜杠。。