extjs分页小例子

前台jsp代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'ext.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

	<link rel="stylesheet" type="text/css" href="<%=basePath%>ext/resources/css/ext-all.css">
	<script type="text/javascript" src="<%=basePath%>ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=basePath%>ext/ext-all.js"></script>
    <script type="text/javascript" src="<%=basePath%>ext/ext-lang-zh_CN.js"></script>
    <script type="text/javascript">
    Ext.onReady(function(){
        var store=new Ext.data.JsonStore({
	           url:"<%=basePath%>lpm/step2.action",
	           autoLoad:{params:{start:0,limit:10}},  //传递到后台的参数
	           fields:["userid","name"],
	           root:"data",                         //从后台取得的数据
	           totalProperty:"count"                //从后台取得的数据总量
        });

		var column=new Ext.grid.ColumnModel(
			[
			{header:"编号",dataIndex:"userid",sortable:true},
			{header:"姓名",dataIndex:"name",sortable:true}
			]
		);
		
		var grid = new Ext.grid.GridPanel({
			renderTo:"hello",
			title:"Hello world",
			height:300,
			width:470,
			cm:column,
			store:store,
			autoExpandColumn:0,
			loadMask:true,
			frame:true,
			autoScroll:true,
			bbar:new Ext.PagingToolbar({
				pageSize:10,   
				store:store, 
	            displayInfo: true,    
	            displayMsg: '显示 {0}-{1}条记录,共 {2} 条',    
	            emptyMsg: "没有记录"  
			
			}) 
	
        });

        
   })
    </script>
  </head>
  
  <body>
    <div id="hello"></div>
  </body>
</html>

 后台action代码:

package com.china.action;


import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("/lpm")
public class Lpmcon extends ActionSupport{	
	@Action(value="step2"
			)
	public String getRes2(){
		HttpServletRequest request=ServletActionContext.getRequest();
		try{
			EntityManagerFactory ef=Persistence.createEntityManagerFactory("mysql");
		    EntityManager em=ef.createEntityManager();
		    Query qu=em.createQuery("from persion order by userid");
		    int count=qu.getResultList().size();
		   // List list=qu.getResultList();
		   
		    String start=request.getParameter("start");
		    String limit=request.getParameter("limit");
		    List list=qu.setFirstResult(Integer.parseInt(start))
			            .setMaxResults(Integer.parseInt(limit))
			            .getResultList();
		    
		    Map map=new HashMap();
		    map.put("data", list);
		    map.put("count",count);
		    JSONObject jalist=JSONObject.fromObject(map);
		    System.out.println(jalist.toString());
		    
		    HttpServletResponse hsr=ServletActionContext.getResponse();
		    PrintWriter pw=hsr.getWriter();
		    pw.print(jalist.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	
		
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值