package demofy;import java.io.*;
import java.util.*;public class DemoFY implements Serializable {
/**分页代码start*/
int intPageSize = 20; //一页显示的记录数
int intRowCount = 0; //记录总数intRowCount
int intPageCount = 0; //总页数
int intPage = 0; //当前显示的页面数
String strPage = "";
ArrayList ar = null;
/**分页代码end*/
public DemoFY(ArrayList ar,int intPageSize) {
this.ar = ar;
        this.intPageSize=intPageSize;
        intRowCount=ar.size();
} /**
 *
 * 分页代码
 *
 * */
public void init() {
if (strPage == null) { //表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
} else { //将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if (intPage < 1) {
intPage = 1;
}
} }
    /**
         * 
         * page为要跳转的页面
         * */
public String printPage(String page) {
StringBuffer returnStr = new StringBuffer();
returnStr.append("总页数/总记录 " + intPageCount + "/" + intRowCount +
 "&nbsp;&nbsp");
if (intPageCount == 1) {
returnStr.append("<font class='gray3'>&nbsp;&lt;&lt;&nbsp;</font>");
} else {
returnStr.append("<a href='"+page+"'?page=1&&action=2' class='GrayToOra'>&nbsp;&lt;&lt;&nbsp;</a>");
}
//--------------------------------------------------------------------------------
for (int k = 1; k <= intPageCount; k++) {
if (intPage == k) {
returnStr.append("<font class='red12'>&nbsp;" + k +
 "&nbsp;</font>");
} else {
returnStr.append(
 " <a href='"+page+"'.jsp?page=<%=k%>&&action=2' class='GrayToOra'>&nbsp;" +
 k + "&nbsp;</a>");
}
}
//---------------------------------------------------------------------------------
if (intPageCount == 1) {
returnStr.append(" <font class='gray3'>&nbsp;&gt;&gt;&nbsp;</font>");
} else {
returnStr.append("<a href='"+page+"?page=" + intPageCount +
 "&&action=2' class='GrayToOra'>&nbsp;&gt;&gt;&nbsp;</a>");
}
        return returnStr.toString();
} private void readObject(ObjectInputStream ois) throws IOException,
 ClassNotFoundException {
ois.defaultReadObject();
} private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
} public int getIntPage() {
return intPage;
} public int getIntPageCount() {
return intPageCount;
} public int getIntPageSize() {
return intPageSize;
} public int getIntRowCount() {
return intRowCount;
} public void setIntPage(int intPage) {
this.intPage = intPage;
} public void setIntPageCount(int intPageCount) {
this.intPageCount = intPageCount;
} public void setIntPageSize(int intPageSize) {
this.intPageSize = intPageSize;
} public void setIntRowCount(int intRowCount) {
this.intRowCount = intRowCount;
}
}
给个代码参考一下,中间循环部份,还要自己解决一下