有一个页面请求action,action调用分页实现类,然后到显示分页页面
1.以下是实现分页的类PageResultSet
package page.bean;
import java.util.*;
public class PageResultSet {
/**
* 分页数据
*/
private Collection data = null;
/**
* 当前页
*/
private int curPage;
/**
* 每页显示的记录数
*/
private int pageSize;
/**
* 记录行数
*/
private int rowsCount;
/**
* 页数
*/
private int pageCount;
public PageResultSet(Collection data) {
this.data = data;
this.curPage = 1;
this.pageSize = 10;
this.rowsCount = data.size();
this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
}
public PageResultSet(Collection data, int curPage) {
this.data = data;
this.curPage = curPage;
this.pageSize = 10;
this.rowsCount = data.size();
this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
}
public PageResultSet(Collection data, int curPage, int pageSize) {
this.data = data;
this.curPage = curPage;
this.pageSize = pageSize;
this.rowsCount = data.size();
this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
}
/**
* getCurPage:返回当前的页数
*
* @return int
*/
public int getCurPage() {
return curPage;
}
/**
* getPageSize:返回分页大小
*
* @return int
*/
public int getPageSize() {
return pageSize;
}
/**
* getRowsCount:返回总记录行数
*
* @return int
*/
public int getRowsCount() {
return rowsCount;
}
/**
* getPageCount:返回总页数
*
* @return int
*/
public int getPageCount() {
return pageCount;
}
/**
* 第一页
*
* @return int
*/
public int first() {
return 1;
}
/**
* 最后一页
*
* @return int
*/
public int last() {
return pageCount;
}
/**
* 上一页
*
* @return int
*/
public int previous() {
return (curPage - 1 < 1) ? 1 : curPage - 1;
}
/**
* 下一页
*
* @return int
*/
public int next() {
return (curPage + 1 > pageCount) ? pageCount : curPage + 1;
}
/**
* 第一页
*
* @return boolean
*/
public boolean isFirst() {
return (curPage == 1) ? true : false;
}
/**
* 最后一页
*
* @return boolean
*/
public boolean isLast() {
return (curPage == pageCount) ? true : false;
}
/**
相关专题
- 解析Servlet/JSP会话跟踪机制 (65次浏览)
- JSP/Servlet/JSF中对标签库的深入研究 (22次浏览)
- 介绍JSP中表单数据存储应用的一种通用方法 (19次浏览)
- 在JSP环境中如何配置和使用fckeditor (16次浏览)
- 深入讲解JSP 2.0下的动态内容缓存技术 (14次浏览)
- 用JSP写出FileUpload上传小程序 (11次浏览)
- 利用缓冲技术提高JSP程序的性能和稳定性 (11次浏览)
- JSP/Servlet:Servlet/JSP会话跟踪机制 (11次浏览)
- JSP/Servlet/JSF--对标签库的深入研究 (10次浏览)
- JSP过滤器实现---论坛不文明语过滤功能 (9次浏览)



