java分页导航条代码 java分页实现原理( 二 )


//如果当前页不是第1页,则显示第一页和前一页的链接
if(PageNo != 1){
PrevStart = PageNo - 1;
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo=1第一页 /a:");
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+PrevStart+"前一页/a");
}
out.print("[");
//打印需要显示的页码
for(int c=CounterStart;c=CounterEnd;c++){
if(c MaxPage){
if(c == PageNo){
if(c %PageSize == 0){
out.print(c);
}else{
out.print(c+" ,");
}
}else if(c % PageSize == 0){
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+c+""+c+"/a");
}else{
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+c+""+c+"/a ,");
}
}else{
if(PageNo == MaxPage){
out.print(c);
break;
}else{
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+c+""+c+"/a");
break;
}
}
}
out.print("]");;
if(PageNoMaxPage){ //如果当前页不是最后一页,则显示下一页链接
NextPage = PageNo + 1;
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+NextPage+"下一页/a");
}
//同时如果当前页不是最后一页,要显示最后一页的链接
if(PageNoMaxPage){
LastRec = RecordCount % PageSize;
if(LastRec == 0){
LastStartRecord = RecordCount - PageSize;
}
else{
LastStartRecord = RecordCount - LastRec;
}
out.print(":");
out.print("a href=https://www.04ip.com/post/TestPage.jsp?PageNo="+MaxPage+"最后一页/a");
}
out.print("/font");
%
/div
/td
/tr
/table
%
rs.close();
statement.close();
connection.close();
%
/body
/html
谁能给我个完整的java 分页代码 谢谢了import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.lqh.dao.db.DBCon;
public class PageDAO {
public static final String Text = "text";
public static final String Image = "image";
public static final String BbsText = "bbstext";
public static final String BbsImage = "bbsimage";
private HttpServletRequest request;
private int currentpage = 1; // 当前是第几页
private int pagecount = 0; // 一共有多少页
private int rscount = 0; // 一共有多少行
private int pagesize = 10; // 每页有多少行[默认为20行]
public PageDAO(HttpServletRequest request) {
this.request = request;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getRscount() {
return rscount;
}
public void setRscount(int rscount) {
this.rscount = rscount;
}
/**
* 传入SQL语句获取总记录数
*/
public int getRsCountForRs(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
rs.last();
this.rscount = rs.getRow();
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);

推荐阅读