当前位置:编程学习 > JAVA >>

jsp分页组件跳转不到下一页,贴出代码大侠指出错误

package dao;

import java.util.List;

public class PageListData {

private List dataList = null;// 分页结果集

private int totalcount = 0;// 记录总数

private int pageSize = 0;// 每页显示记录数

private int currentPage = 1;// 当前页数

private int totalPageCount = 1;// 总页数

private String footer;// 分页页脚

/* 初始化分页组件 */
public PageListData(int totalcount, int pageSize, int currentPage, List dataList) {
setTotalcount(totalcount);
setPageSize(pageSize);
setCurrentPage(currentPage);
setDataList(dataList);
setFooter(getFooter());
}

/**
 * 封装分页栏函数 必需被包含在某个Form之中
 * 
 * @return String pages 当前页号 pageSize 每页显示行数
 */
public String getFooter() {
StringBuffer pageStr = new StringBuffer("");
int totalPages = getTotalPageCount(); // 总页数
int prevPage = currentPage - 1; // 上一页
int nextPage = currentPage + 1; // 下一页


pageStr.append("<tr><td height='35' background='images/tab_19.gif'><table class='pages' width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='12' height='35'><img src='images/tab_18.gif' width='12' height='35' /></td><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>");
pageStr.append("<td class='STYLE4'>  共有 " + totalcount + " 条记录,当前第  " + currentPage + "/" + totalPages + " 页</td>");
pageStr.append("<td><table border='0' align='right' cellpadding='0' cellspacing='0'><tr>");
if (currentPage > 1)
pageStr.append("<td width='40'><img src='images/first.gif' onclick='document.getElementById(\"pages\").value=1;document.getElementById(\"pages\").form.submit();' width='37' height='15' style='cursor:hand;'/></td>");
if (currentPage == 1)
pageStr.append("<td width='40'><img src='images/first.gif' width='37' height='15' style='cursor:hand;' /></td>");
if (currentPage > 1)
pageStr.append("<td width='45'><img src='images/back.gif' onclick='document.getElementById(\"pages\").value=" + prevPage + ";document.getElementById(\"pages\").form.submit();' width='43' height='15' style='cursor:hand;'/></td>");
if (currentPage <= 1)
pageStr.append("<td width='45'><img src='images/back.gif' width='43' height='15' style='cursor:hand;'/></td>");
if (currentPage < totalPages)
pageStr.append("<td width='45'><img src='images/next.gif' onclick='document.getElementById(\"pages\").value=" + nextPage + ";document.getElementById(\"pages\").form.submit();' width='43' height='15' style='cursor:hand;'/></td>");
if (currentPage >= totalPages)
pageStr.append("<td width='45'><img src='images/next.gif' width='43' height='15' style='cursor:hand;'/></td>");
if (currentPage < totalPages)
pageStr.append("<td width='40'><img src='images/last.gif' onclick='document.getElementById(\"pages\").value=" + totalPages + ";document.getElementById(\"pages\").form.submit();' width='37' height='15' style='cursor:hand;'/></td>");
if (currentPage == totalPages)
pageStr.append("<td width='40'><img src='images/last.gif' width='37' height='15' style='cursor:hand;'/></td>");

pageStr.append("<td width='100'><div align='center'><span class='STYLE1'>转到第 <input name='textfield' onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\\D/g,'')\" onblur='checkCurrentPage(document.getElementById(\"jumpPageBox\").value," + totalPages + ")' value='" + currentPage + "' id='jumpPageBox' type='text' size='4' style='height:17px; width:20px; border:1px solid #999999;' /> 页 </span></div></td>");
pageStr.append("<td width='40'><img src='images/go.gif' onclick='document.getElementById(\"pages\").value=document.getElementById(\"jumpPageBox\").value;document.getElementById(\"pages\").form.submit();'  width='37' height='15' style='cursor:hand;'/></td>");
pageStr.append("</tr></table></td></tr></table></td><td width='16'><img src='images/tab_20.gif' width='16' height='35' style='cursor:hand;'/></td></tr></table></td></tr>");

pageStr.append("<input type='hidden' value='" + currentPage + "' name='currentPage' id='pages' />");
pageStr.append("<input type='hidden' value='" + pageSize + "' name='pageSize' id='pageSize' />");
System.out.println("pageStr:" + pageStr.toString());
return pageStr.toString();
}

public List getDataList() {
return dataList;
}

public void setDataList(List dataList) {
this.dataList = dataList;
}

public int getTotalcount() {
return totalcount;
}

public void setTotalcount(int totalcount) {
this.totalcount = totalcount;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public int getCurrentPage() {
return currentPage;
}

public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}

// 计算总页数,如果为0则置为1
public int getTotalPageCount() {
int p;
if (totalcount % pageSize == 0) {
p = totalcount / pageSize;
} else {
p = totalcount / pageSize + 1;
}
return p == 0 ? 1 : p;
}

public void setTotalPageCount(int totalPageCount) {
this.totalPageCount = totalPageCount;
}

public void setFooter(String footer) {
this.footer = footer;
}

}
--------------------编程问答-------------------- 光看这个JAVA类是看不出问题的,你前台调用呢 --------------------编程问答-------------------- 你先梳理下你的思路吧!先弄明白分页功能中哪些事是在前台做的哪些事是在后台做的;一般后台只负责接收前台传递过来的查询的页数以及每页显示的行数;然后拿这2个参数去查询到相应的结果集返回给前台;至于获取要查询的页数以及每页显示的行数则放在前台来做
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,