如题
后台使用的是SSH框架,前台想用Ext呈现后台数据,数据已经能正常获取,但是没有显示出来,不知道是哪里配错了,按着网上
http://www.blogjava.net/fuhoujun/archive/2008/10/02/232050.html 的步骤做的 JSP页面能显示数据如图
下面是代码
Struts逻辑代码:
Struts.xml
JS代码:
JSP:
目前迷惑的是 JSP起到的中转数据的作用吗,该怎么用,最后呈现的页面代码好像不能跟该JSP页面在同一个?
劳烦大家帮忙看看
后台使用的是SSH框架,前台想用Ext呈现后台数据,数据已经能正常获取,但是没有显示出来,不知道是哪里配错了,按着网上
http://www.blogjava.net/fuhoujun/archive/2008/10/02/232050.html 的步骤做的 JSP页面能显示数据如图
![](http://img.bbs.csdn.net/upload/201403/22/1395474925_238580.png)
下面是代码
Struts逻辑代码:
public String execute()
{
List<Room> roomlist=roomService.findAllRoom();
ServletActionContext.getRequest().setAttribute("roomlist", roomlist);
System.out.println("查找完毕");
this.setTotalCount(roomlist.size());
JSONArray array=JSONArray.fromObject(roomlist);
this.jsonString="{totalCount:"+this.getTotalCount()+",results:"+array.toString()+"}";
/*return SUCCESS;*/
System.out.println("转换完毕");
return SUCCESS;
Struts.xml
<action name="listRoom" class="ListRoom">
<result name="success" type="json"/>
<param name="jsonString">/ext_form.jsp</param>
</action>
JS代码:
Ext.onReady(function(){
Ext.define('Room',
{
extend:'Ext.data.Model',
fields:[{
name:'roomid',type:'int'
},
{
name:'roomname',type:'string'
},
{
name:'price',type:'int'
},
{
name:'category',type:'string'
},
{name:'status',type:'int'}]
});
var rd = new Ext.data.JsonReader({
//总记录数
totalProperty: 'totalCount',
//哪儿是数据的头,可以看action里面是怎么定义数据格式的,这里就是如何解析的
root: 'results',
id:'roomid',
//有那些字段呢?
fields:[
/* {name:'roomid'},
{name:'roomname'},
{name:'price'},
{name:'category'},
{name:'status'},*/
//这里就是对room对象进行映射的地方
{name:'roomid' ,mapping:'Room.roomid'},
{name:'roomname',mapping:'Room.roomname'},
{name:'price',mapping:'Room.price'},
{name:'category',mapping:'Room.category'},
{name:'status',mapping:'Room.status'}
]
});
var roomstore=Ext.create('Ext.data.Store',{
model:"Room",
pagesize:2,
proxy:{
type:'ajax',
url:'listRoom.action',
method:'POST',
reader:rd
/*new Ext.data.JsonReader( {
totalProperty:totalCount,
root:results,
id:'roomid'
},
[
{name:'rooid',mapping:'roomid'},
{name:'roomname',mapping:'roomname'},
{name:'price',mapping:'price'},
{name:'category',mapping:'category'},
{name:'status',mapping:'status'}
])*/
},
autoLoad:true
});
roomstore.load();
Ext.create('Ext.grid.Panel',{
title:'房间信息',
store:roomstore,
columns:[
{header:'房间号',dataIndex:'roomid'},
{header:'房间名',dataIndex:'roomname'},
{header:'价格',dataIndex:'price'},
{header:'房间类型',dataIndex:'category'},
{header:'房间状态',dataIndex:'status'}
],
width:600,
bbar:{
xtype:'pagingtoolbar',
store:roomstore,
displayInfo:true
},
renderTo:Ext.getBody()
});
});
JSP:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%-- <%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> --%>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:property value="jsonString" escape="false" />
<!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=GB18030">
<link href="ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ext/ext-all.js"></script>
<%-- <script type="text/javascript" src="ext/ext-lang-zh_CN.js"></script> --%>
<script type="text/javascript" src="listroom.js"></script>
<title>ext表单</title>
</head>
目前迷惑的是 JSP起到的中转数据的作用吗,该怎么用,最后呈现的页面代码好像不能跟该JSP页面在同一个?
劳烦大家帮忙看看