最近在用ext,可遇到了一个很奇怪的问题
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
- request.getServerName() + ":" + request.getServerPort()
-
path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
href="resources/css/ext-all.css" /><br> function renderSex(value) {<br> if (value == 'male') {<br> return " <span style='color:red;font-weight:bold;'>红男 </span> <img src='user_male.png' />";<br> } else {<br> return " <span style='color:green;font-weight:bold;'>绿女 </span> <img src='user_female.png' />";<br> }<br> }<br> function renderDescn(value, cellmeta, record, rowIndex, columnIndex, store) {<br> var str = " <input type='button' value='查看详细信息' onclick='alert(\"" +<br> "这个单元格的值是:" + value + "\\n" +<br> "这个单元格的配置是:{cellId:" + cellmeta.cellId + ",id:" + cellmeta.id + ",css:" + cellmeta.css + "}\\n" +<br> "这个单元格对应行的record是:" + record + ",一行的数据都在里边\\n" +<br> "这是第" + rowIndex + "行\\n" +<br> "这是第" + columnIndex + "列\\n" +<br> "这个表格对应的Ext.data.Store在这里:" + store + ",随便用吧。" +<br> "\")'>";<br> return str;<br> }</p> <pre><code>Ext.onReady(function(){ </code></pre> <p>var sm = new Ext.grid.CheckboxSelectionModel();<br> var cm = new Ext.grid.ColumnModel([<br> new Ext.grid.RowNumberer(),<br> sm,<br> {header:'编号',dataIndex:'id',sortable:true},<br> {header:'性别',dataIndex:'sex',sortable:true,renderer:renderSex},<br> {header:'名称',dataIndex:'name',sortable:true},<br> {header:'描述',dataIndex:'descn',sortable:true,renderer:renderDescn}<br> ]);<br> var ds = new Ext.data.Store({<br> proxy: new Ext.data.HttpProxy({url:'gird.jsp'}),<br> reader: new Ext.data.JsonReader({<br> totalProperty: 'totalProperty',<br> root: 'root'<br> },[<br> {name: 'id',mapping:0},<br> {name: 'sex',mapping:1},<br> {name: 'name',mapping:2},<br> {name: 'descn',mapping:3}<br> ])<br> });</p></li> </ul> <p>var grid = new Ext.grid.GridPanel({<br> renderTo: 'grid',<br> height:500,<br> ds: ds,<br> cm: cm,<br> sm: sm,<br> bbar: new Ext.PagingToolbar({<br> pageSize: 2,<br> store: ds,<br> displayInfo: true,<br> displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',<br> emptyMsg: "没有记录"<br> })<br> });<br> ds.load({params:{start:0,limit:2}});<br> grid.render();<br> });<br>
gird.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String start = request.getParameter("start");
String limit = request.getParameter("limit");
System.out.println("start=" + start);
System.out.println("limit=" + limit);
try {
int index = Integer.parseInt(start);
int pageSize = Integer.parseInt(limit);String json = "{totalProperty:100,root:["; for (int i = index; i < pageSize + index; i++) { json += "{id:" + i + ",sex:'sex" + i + "',name:'name" + i + "',descn:'descn" + i + "'}"; if (i != pageSize + index - 1) { json += ","; } } json += "]}"; System.out.println("json===" + json); response.getWriter().write(json); response.getWriter().close();
} catch(Exception ex) {
}
%>刷新index.jsp打印出来
start=0
limit=2
json==={totalProperty:100,root:[{id:0,sex:'sex0',name:'name0',descn:'descn0'},{id:1,sex:'sex1',name:'name1',descn:'descn1'}]}点分页的下一页打印出
start=2
limit=2
json==={totalProperty:100,root:[{id:2,sex:'sex2',name:'name2',descn:'descn2'},{id:3,sex:'sex3',name:'name3',descn:'descn3'}]}可页面gird里就是没有数据,分页有效 gird.jsp里的json是出来了,但index.jsp里的ext接收不到数据,表格里就是没数据显示,但表格也只显示2列,就是没实际的数据结果
这是为什么?