JSP怎样实现分页
有几种方式
谢谢

解决方案 »

  1.   

    本人最近写的一个分页显示:采用JavaBean实现的。你可以认真想一下,分页显示真正需要的是哪些数据。一:总页数totalPages,其实是通过数据库信息,已经可以得到的;二:当前页currentPage,是通过页数传递的。至于其它,如一页显示多少条记录pageSize、本页开始的那条记录beginEnd和结束的那条记录endRecord。所以,只要传一个值就可以实现分页显示。
      

  2.   

    其它的值都可以通过totalPages和currentPage算出来。
      

  3.   

    JavaBean的代码:
    public class PageBean {
    //每页显示数
    public final int pageSize = 10;
    //记录总数
    public int totalRecord;
    //总页数
    public int totalPage;
    //当前页
    public int currentPage;
    //每页开头行
    public int beginRow;
    //每页结束行
    public int endRow;

    //页的位数
    public int digitPage;

    public PageBean(){
    currentPage = 1;
    //数据库Discount表的总记录数
    DiscountDaoImpl ddi = new DiscountDaoImpl();
    totalRecord = ddi.getDiscountInfo().size();

    totalPage = (totalRecord % pageSize == 0) ? (totalRecord / pageSize) : ((totalRecord / pageSize) + 1);
    beginRow = 0;
    endRow = 9;
    }

    public int getCurrentPage() {
    return currentPage;
    }
    public void setCurrentPage(int currentPage) {
    if(currentPage <= 0){
    currentPage = 1;
    }
    if(currentPage > totalPage){
    currentPage = totalPage;
    }
    this.currentPage = currentPage;
    }

    public int getTotalRecord() {
    return totalRecord;
    }
    public int getBeginRow() {
    return (currentPage - 1) * pageSize;
    }
    public int getEndRow() {
    return currentPage * pageSize - 1;
    }
    public int getTotalPage() {
    return totalPage;
    }
    }