java分页代码和效果 java分页显示( 二 )


ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
this.rscount = rs.getInt("rscount");
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
/**
* 获取总页数
*
* @return int
*/
public int getPageCount() {
try {
this.pagecount = ((this.rscount - 1) / this.pagesize) + 1;
} catch (Exception ex) {
this.pagecount = 0;
}
return this.pagecount;
}
/**
* 获取当前页码的设置
*
* @return int
*/
public int getCurrentPage() {
try {
if (this.request.getParameter("currentpage") != null
Integer.parseInt(this.request
.getParameter("currentpage"))1) {
this.currentpage = Integer.parseInt(this.request
.getParameter("currentpage"));
} else {
this.currentpage = 1;
}
} catch (Exception ex) {
this.currentpage = 1;
}
return this.currentpage;
}
/**
* 分页工具条
*
* @param fileName
*String
* @return String
*/
public String pagetool(String flag) {
StringBuffer str = new StringBuffer();
String url = this.getParamUrl();
int ProPage = this.currentpage - 1;
int Nextpage = this.currentpage + 1;
// 文字的分页
if (flag.equals(PageDAO.Text)) {
str.append("form method='post' name='pageform' action=''");
str
.append("table style='color: windowframe' width='100%' border='0' cellspacing='0' cellpadding='0'");
str.append("tr");
str.append("td width='20%'/td");
str.append("td height='26'");
str.append("共有记录" + this.rscount + "条 ");
str.append("共" + this.pagecount + "页 ");
str.append("每页" + this.pagesize + "记录 ");
str.append("现在" + this.currentpage + "/" + this.pagecount + "页");
str.append("/tdtd");
if (this.currentpage1) {
str.append("a href='" + url + "currentpage=1'首页/a");
str.append(" ");
str.append("a href='" + url + "currentpage=" + ProPage
+ "'上一页/a");
str.append(" ");
} else {
str.append("首页");
str.append(" ");
str.append("上一页");
str.append(" ");
}
if (this.currentpagethis.pagecount) {
str.append("a href='" + url + "currentpage=" + Nextpage
+ "'下一页/a");
str.append(" ");
} else {
str.append("下一页");
str.append(" ");
}
if (this.pagecount1this.currentpage != this.pagecount) {
str.append("a href='" + url + "currentpage=" + pagecount
+ "'尾页/a");
str.append(" ");
} else {
str.append("尾页");
str.append(" ");
}
str.append("转到");
str
.append("select name='currentpage' onchange='javascript:ChangePage(this.value);'");
for (int j = 1; j = pagecount; j++) {
str.append("option value='" + j + "'");
if (currentpage == j) {
str.append("selected");
}
str.append("");
str.append("" + j + "");
str.append("/option");
}
str.append("/select页");
str.append("/tdtd width='3%' /td/tr/table");
str.append("script language='javascript'");
str.append("function ChangePage(testpage){");
str.append("document.pageform.action='" + url
+ "currentpage='+testpage+'';");
str.append("document.pageform.submit();");
str.append("}");
str.append("/script");
str.append("/form");
} else if (flag.equals(PageDAO.Image)) {
/**
* 图片的分页
*/
} else if (flag.equals(PageDAO.BbsText)) {
/**
* 论坛形式的分页[直接以数字方式体现]
*/
str
.append("table width='100%' border='0' cellspacing='0' cellpadding='0'");

推荐阅读