zoukankan      html  css  js  c++  java
  • 玩转Web之easyui(一)-----easy ui datagird 分页

    easy ui 中数据表格的分页其实是很简单的,分页是在数据表格可以正常显示数据的基础上进行的,在这里给出servlet的代码,其中selectAll()方法是从数据库中提取所有数据,

    分页的一种思路是:从数据表中取出所有数据,然后根据分页的要求取出对应的数据。

    package thejavabean;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import net.sf.json.JSONArray;
    
    public class Table_info extends HttpServlet {
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    
    		try {
    			response.setContentType("text/html");
    			response.setCharacterEncoding("UTF-8");
    			PrintWriter out = response.getWriter();
    			String page = request.getParameter("page"); // 当前页数
    			String rows = request.getParameter("rows"); // 每页显示行数  
    			
    			List<Student> allList=selectAll();   //获取所有数据
    			int p=Integer.parseInt(page);    
    			int r=Integer.parseInt(rows);
    			int begin=(p-1)*r;  //当前页开始项
    			int num=begin;
    			int count=r;
    			List<Student> list=new ArrayList();
    			System.out.println();
    			while(count>0&&num<allList.size()){
    				list.add(allList.get(num)); 
    				num++;
    				count--;
    			}
    			int total=selectAll().size();
    			String json = "{"total":"+total+" , "rows":"+JSONArray.fromObject(list).toString()+"}";
    		    
    			response.getWriter().write(json.toString());
    			out.flush();
    			out.close();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    		
    	}
        public List<Student> selectAll() throws SQLException{
        	StudentManage sm=new StudentManage();
    		return sm.selectAll("");
        	
        }
    	public void doPost(HttpServletRequest request, HttpServletResponse response)
    			throws ServletException, IOException {
    		this.doGet(request, response);
    		
    	}
    
    }
    


     

  • 相关阅读:
    百分比布局中的居中
    struts2常用标签详解
    Struts2常用标签总结
    Struts2中action接收参数的三种方法及ModelDriven跟Preparable接口结合JAVA反射机制的灵活用法
    Dbutils学习(介绍和入门)
    Ajax与JSON的一些总结
    CURD定义
    java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
    a标签设置高度不生效问题
    使用iframe标签时如何通过jquery隐藏滚动条
  • 原文地址:https://www.cnblogs.com/oversea201405/p/3752184.html
Copyright © 2011-2022 走看看