日期:2014-05-19  浏览次数:20608 次

SSH1/2 J2EE 纯Java版分页查询
实体bean---------> PageBean.java
package com.demo.page;

import java.util.List;

public class PageBean {
	
	/*==============================================================*/
	private List resultList;//结果集
	private int recordSUM;//总记录数
	private int pageSUM;//总页数
	private int currentPage;//当前页
	private int pageSize;//页记录数
	private boolean isFirstPage;//是否是第一页   
	private boolean isLastPage;//是否是最后一页
	private boolean hasPreviousPage;//是否有上一页
	private boolean hasNextPage;//是否有下一页
	/*===========================初始化===================================*/
	public void init(){ 
		this.isFirstPage = isFirstPage(); 
	    this.isLastPage = isLastPage(); 
	    this.hasPreviousPage = isHasPreviousPage(); 
	    this.hasNextPage = isHasNextPage(); 
	} 
	/*=============================总页数=================================*/
	public static int countTotalPage(int pageSize,int recordSUM){ 
		
		int totalPage = recordSUM % pageSize == 0 ? recordSUM/pageSize : recordSUM/pageSize+1; 
		
	    return totalPage; 
	} 
	/*============================当前页开始记录号 ==================================*/
	public static int countOffset(final int pageSize,final int currentPage){ 
		
		final int offset = pageSize*(currentPage-1); 
		
	    return offset; 
	} 
	/*=============================当期页=================================*/
	public static int countCurrentPage(int page){ 
		
		final int curPage = (page==0?1:page); 
		
	    return curPage; 
	} 
	/*============================判断当前页的状态==================================*/
	public boolean isFirstPage() { 
		return currentPage == 1;    
	} 
	public boolean isLastPage() { 
	    return currentPage == pageSUM;    
	} 
	public boolean isHasPreviousPage() { 
	    return currentPage != 1;         
	} 
	public boolean isHasNextPage() { 
		return currentPage != pageSUM;    
	} 
	/*===========================Get/Set方法===================================*/
	public List getResultList() {
		return resultList;
	}
	public void setResultList(List resultList) {
		this.resultList = resultList;
	}
	public int getRecordSUM() {
		return recordSUM;
	}
	public void setRecordSUM(int recordSUM) {
		this.recordSUM = recordSUM;
	}
	public int getPageSUM() {
		return pageSUM;
	}
	public void setPageSUM(int pageSUM) {
		this.pageSUM = pageSUM;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/*==============================================================*/
     
}

JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'listUser.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">

  </head>
  
  <body>
 	  <table border="" >
 		<tr>
 	 		<td><input type="checkbox"></td><td>用户名</td><td>密码</td><td>性别</td><td>年龄</td><td>邮箱</td><td>地址</td>
 	 	</tr>
 	 <s:iterator value="resultList" id="user">
 	 	<tr>
 	 		<td><input type="checkbox"></td>
 	 		<td><s:property value="#user.username"/></td&