JSP分页程序
---摘自书本实例
package
com.zh.util;
import com.zh.conpool.Condata;
import java.sql.ResultSet;
import java.sql.SQLException;
public class page
... {
ResultSet rs;
ResultSet rst;
private int intCountTopic;
public int intPageSize;
public int intPageCount;
public int intPage;
private String Countsql;
private String Pagisql;
private String str;
private String str_where;
private String str_parameter;
private String nowPage;
private String HttpFile;
Condata db;
public page()
...{
rs = null;
rst = null;
intCountTopic = 0;
intPage = 0;
Countsql = null;
Pagisql = null;
str = null;
str_where = null;
str_parameter = "";
db = new Condata();
}
public static void main(String args[])
...{
}
public void setPages(int i)
...{
intPageSize = i;
}
public String getPagisql()
...{
return Pagisql;
}
public ResultSet setQuerysql(String s, String s1, String s2, String s3)
throws SQLException
...{
ResultSet resultset = null;
nowPage = s3;
HttpFile = s2;
Countsql = "select count(*) from " + s + " " + s1;
Pagisql = "select * from " + s + " " + s1 + " order by id desc";
try
...{
Condata _tmp = db;
Condata.getConnection();
}
catch(Exception exception)
...{
exception.getMessage();
}
try
...{
resultset = querySql(Countsql, Pagisql);
}
catch(SQLException sqlexception)
...{
sqlexception.getMessage();
}
return resultset;
}
public ResultSet querySql(String s, String s1)
throws SQLException
...{
try
...{
Condata condata = db;
Condata.getConnection();
}
catch(Exception exception) ...{ }
if(nowPage == null)
...{
intPage = 1;
} else
...{
intPage = Integer.parseInt(nowPage);
if(intPage < 1)
intPage = 1;
}
rs = db.executeQuery(s);
if(rs.next())
intCountTopic = rs.getInt(1);
intPageCount = intCountTopic % intPageSize == 0 ? intCountTopic / intPageSize : intCountTopic / intPageSize + 1;
if(intPage > intPageCount)
intPage = intPageCount;
rs.close();
rst = db.executeQuery(s1);
return rst;
}
public int getCountTopic()
...{
return intCountTopic;
}
public int getPageCount()
...{
return intPageCount;
}
public int getIntPage()
...{
return intPage;
}
public String PageFooter()
...{
String s = "<form action=" + HttpFile + " name=form1 methord=post>";
int i = intPage - 1;
int j = intPage + 1;
int k = (intPageSize * getIntPage() + 1) - intPageSize;
if(k < 0)
k = 0;
s = s + "<font style='font-size: 9pt'>总计<font color='red'>" + getCountTopic() + "</font>条记录," + "【共<font color='red'>" + getPageCount() + "</font>页】";
s = s + "【" + intPageSize + "条/页】 当前第<font color='red'>" + getIntPage() + "</font>页(列出第" + k + "到第" + getIntPage() * intPageSize + "条) ";
if(intPage > 1)
s = s + " <A href=" + HttpFile + "?pages=1" + str_parameter + ">首页</A> ";
else
s = s + " 首页 ";
if(intPage > 1)
s = s + " <A href=" + HttpFile + "?pages=" + i + str_parameter + ">上一页</A> ";
else
s = s + " 上一页 ";
if(intPage < intPageCount)
s = s + " <A href=" + HttpFile + "?pages=" + j + str_parameter + ">下一页</A> ";
else
s = s + " 下一页 ";
if(intPageCount > 1 && intPage != intPageCount)
s = s + " <A href=" + HttpFile + "?pages=" + intPageCount + str_parameter + ">尾页</A>";
else
s = s + " 尾页</font>";
s = s + "</form>";
return s;
}
public void closeConn()
...{
db.close();
}
}
import com.zh.conpool.Condata;
import java.sql.ResultSet;
import java.sql.SQLException;
public class page
... {
ResultSet rs;
ResultSet rst;
private int intCountTopic;
public int intPageSize;
public int intPageCount;
public int intPage;
private String Countsql;
private String Pagisql;
private String str;
private String str_where;
private String str_parameter;
private String nowPage;
private String HttpFile;
Condata db;
public page()
...{
rs = null;
rst = null;
intCountTopic = 0;
intPage = 0;
Countsql = null;
Pagisql = null;
str = null;
str_where = null;
str_parameter = "";
db = new Condata();
}
public static void main(String args[])
...{
}
public void setPages(int i)
...{
intPageSize = i;
}
public String getPagisql()
...{
return Pagisql;
}
public ResultSet setQuerysql(String s, String s1, String s2, String s3)
throws SQLException
...{
ResultSet resultset = null;
nowPage = s3;
HttpFile = s2;
Countsql = "select count(*) from " + s + " " + s1;
Pagisql = "select * from " + s + " " + s1 + " order by id desc";
try
...{
Condata _tmp = db;
Condata.getConnection();
}
catch(Exception exception)
...{
exception.getMessage();
}
try
...{
resultset = querySql(Countsql, Pagisql);
}
catch(SQLException sqlexception)
...{
sqlexception.getMessage();
}
return resultset;
}
public ResultSet querySql(String s, String s1)
throws SQLException
...{
try
...{
Condata condata = db;
Condata.getConnection();
}
catch(Exception exception) ...{ }
if(nowPage == null)
...{
intPage = 1;
} else
...{
intPage = Integer.parseInt(nowPage);
if(intPage < 1)
intPage = 1;
}
rs = db.executeQuery(s);
if(rs.next())
intCountTopic = rs.getInt(1);
intPageCount = intCountTopic % intPageSize == 0 ? intCountTopic / intPageSize : intCountTopic / intPageSize + 1;
if(intPage > intPageCount)
intPage = intPageCount;
rs.close();
rst = db.executeQuery(s1);
return rst;
}
public int getCountTopic()
...{
return intCountTopic;
}
public int getPageCount()
...{
return intPageCount;
}
public int getIntPage()
...{
return intPage;
}
public String PageFooter()
...{
String s = "<form action=" + HttpFile + " name=form1 methord=post>";
int i = intPage - 1;
int j = intPage + 1;
int k = (intPageSize * getIntPage() + 1) - intPageSize;
if(k < 0)
k = 0;
s = s + "<font style='font-size: 9pt'>总计<font color='red'>" + getCountTopic() + "</font>条记录," + "【共<font color='red'>" + getPageCount() + "</font>页】";
s = s + "【" + intPageSize + "条/页】 当前第<font color='red'>" + getIntPage() + "</font>页(列出第" + k + "到第" + getIntPage() * intPageSize + "条) ";
if(intPage > 1)
s = s + " <A href=" + HttpFile + "?pages=1" + str_parameter + ">首页</A> ";
else
s = s + " 首页 ";
if(intPage > 1)
s = s + " <A href=" + HttpFile + "?pages=" + i + str_parameter + ">上一页</A> ";
else
s = s + " 上一页 ";
if(intPage < intPageCount)
s = s + " <A href=" + HttpFile + "?pages=" + j + str_parameter + ">下一页</A> ";
else
s = s + " 下一页 ";
if(intPageCount > 1 && intPage != intPageCount)
s = s + " <A href=" + HttpFile + "?pages=" + intPageCount + str_parameter + ">尾页</A>";
else
s = s + " 尾页</font>";
s = s + "</form>";
return s;
}
public void closeConn()
...{
db.close();
}
}