隐藏了部分无关数据
传输的对象
public class PageBean {
private List list;
private int allRow;
private int totalPage;
private int currentPage;
private int pageSize;
private boolean isFirstPage;
private boolean isLastPage;
private boolean hasPrevPage;
private boolean hasNextPage;
****get or set******
}
action
public class YhjsAction extends ActionSupport implements ActionFinal,ValidationWorkflowAware{
/**
* 封装的分页信息
*/
private PageBean pageBean;
/**
* 通过JQuery获取json数据方法
* @return json
* @throws Exception
*/
public String data() throws Exception{
//调用分页服务获取分装的页面数据
pageBean=yhjsPageSer.queryForPage(PageBean.getDemoPageSize(), 1);
return ActionFinal.JSON;
}
struts xml 配置
<action name="yhjs" class="com.drp.action.YhjsAction">
<!-- 返回json数据页面 -->
<result name="json" type="json" >
<param name="root">pageBean</param>
<!-- 包含序列化的属性 -->
<param name="includeProperties">*</param>
<!-- 父类序列化的属性 -->
<param name="ignoreHierarchy">false</param>
<!-- 不包含空值属性 -->
<param name="excludeNullProperties">true</param>
</result>
</action>
jsp页面
<script type="text/javascript" src="<%=getServletContext().getContextPath()%>/script/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(function()
{
getData();
})
function getData()
{
$.ajax({
type:"post",
url:"yhjs/yhjs!data.action",
dateType:"html",
success:function(returnedData){
for(var i=0;i<returnedData.list.length;++i){
var yhjs=returnedData.list[i];
var id=yhjs.id;
var jsmc=yhjs.jsmc;
var yx=yhjs.yx;
var html="<tr id='tableData'><td>"+(i+1)+"</td>";
html+="<td><checkbox /></td>";
html+="<td>"+jsmc+"</td>";
html+="<td>"+yx+"</td>";
$("#show").append(html);
alert(html);
}
}
})
}
</script>