首先,我说明一下错原因:程序运行正常,没有报错,可是不到下一页,求解
TeamPage.java
package com.fonytech.team.page;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.fonytech.vo.Team;
public class TeamPage {
int currentPage=1; //当前页
public int totalPages=0; //总页数
int pageRecorders=5;//每页5条数据
int totalRows=0; //总数据数
int pageStartRow=0;//每页的起始数
int pageEndRow=0; //每页显示数据的终止数
boolean hasNextPage=false; //是否有下一页
boolean hasPreviousPage=false; //是否有前一页
List arrayList;
Iterator it;
public TeamPage(){} public TeamPage(List arrayList){
this.arrayList=arrayList;
totalRows=arrayList.size();
it=arrayList.iterator();
hasPreviousPage=false;
currentPage=1;
if((totalRows%pageRecorders)==0)
{
totalPages=totalRows/pageRecorders;
}
else
{
totalPages=totalRows/pageRecorders+1;
} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if(totalRows<pageRecorders)
{
this.pageStartRow=0;
this.pageEndRow=totalRows;
}
else
{
this.pageStartRow=0;
this.pageEndRow=pageRecorders;
} } /**
* @return Returns the currentPage.
*/
public String getCurrentPage() {
return this.toString(currentPage);
}
/**
* @param currentPage The currentPage to set.
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
/**
* @return Returns the pageRecorders.
*/
public int getPageRecorders() {
return pageRecorders;
}
/**
* @param pageRecorders The pageRecorders to set.
*/
public void setPageRecorders(int pageRecorders) {
this.pageRecorders = pageRecorders;
}
/**
* @return Returns the pageEndRow.
*/
public int getPageEndRow() {
return pageEndRow;
}
/**
* @return Returns the pageStartRow.
*/
public int getPageStartRow() {
return pageStartRow;
}
/**
* @return Returns the totalPages.
*/
public String getTotalPages() { return this.toString(totalPages);
}
/**
* @return Returns the totalRows.
*/
public String getTotalRows() {
return this.toString(totalRows);
}
/**
* @return Returns the hasNextPage.
*/
public boolean isHasNextPage() {
return hasNextPage;
}
/**
* @param hasNextPage The hasNextPage to set.
*/
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
/**
* @return Returns the hasPreviousPage.
*/
public boolean isHasPreviousPage() {
return hasPreviousPage;
}
/**
* @param hasPreviousPage The hasPreviousPage to set.
*/
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public Team[] getNextPage(){
System.out.println("1----------currentPage----------"+currentPage);
currentPage=currentPage+1; //就是在这里,它每次好像都是默认为1了,为什么不变呢,要是可以,就先拿到自己的机器上试一试吧
System.out.println("2----------currentPage----------"+currentPage);
System.out.println("PageBean.getNextPage()正在执行;");
System.out.println("参数currentPage="+currentPage); if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
System.out.println("参数hasNextPage="+hasNextPage);
System.out.println("准备执行PageBean.getBooks()");
Team[] ProductionVos=getProductionVos();
this.description(); return ProductionVos;
} public Team[] getPreviouspage(){ currentPage=currentPage-1; if(currentPage==0){currentPage=1;} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
Team[] pro=getProductionVos();
this.description();
return pro;
} public Team[] getProductionVos(){
System.out.println("pageBean.getProductionVos()开始执行;");
System.out.println("当前页:"+currentPage);
if(currentPage*pageRecorders<totalRows){//判断是否为最后一页
pageEndRow=currentPage*pageRecorders;
pageStartRow=pageEndRow-pageRecorders;
}
else{
pageEndRow=totalRows;
pageStartRow=pageRecorders*(totalPages-1);
}
Team[] ProductionVos=new Team[pageEndRow-pageStartRow+1]; System.out.println("pageStartRow="+pageStartRow);
System.out.println("pageEndRow="+pageEndRow);
int j=0;
for(int i=pageStartRow;i<pageEndRow;i++)
{ Team ProductionVo=(Team)arrayList.get(i);
ProductionVos[j++]=ProductionVo; }
System.out.println("要显示的页面数据已经封装,具体信息如下:");
this.description();
return ProductionVos;
} public String toString(int temp)
{
String str=Integer.toString(temp);
return str;
} public void description()
{ String description="共有数据数:"+this.getTotalRows()+ "共有页数: "+this.getTotalPages() + "当前页数为:"+this.getCurrentPage()+ " 是否有前一页: "+this.isHasPreviousPage() + " 是否有下一页:"+this.isHasNextPage()+ " 开始行数:"+this.getPageStartRow()+ " 终止行数:"+this.getPageEndRow(); System.out.println(description); }
}
TeamPage.java
package com.fonytech.team.page;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.fonytech.vo.Team;
public class TeamPage {
int currentPage=1; //当前页
public int totalPages=0; //总页数
int pageRecorders=5;//每页5条数据
int totalRows=0; //总数据数
int pageStartRow=0;//每页的起始数
int pageEndRow=0; //每页显示数据的终止数
boolean hasNextPage=false; //是否有下一页
boolean hasPreviousPage=false; //是否有前一页
List arrayList;
Iterator it;
public TeamPage(){} public TeamPage(List arrayList){
this.arrayList=arrayList;
totalRows=arrayList.size();
it=arrayList.iterator();
hasPreviousPage=false;
currentPage=1;
if((totalRows%pageRecorders)==0)
{
totalPages=totalRows/pageRecorders;
}
else
{
totalPages=totalRows/pageRecorders+1;
} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if(totalRows<pageRecorders)
{
this.pageStartRow=0;
this.pageEndRow=totalRows;
}
else
{
this.pageStartRow=0;
this.pageEndRow=pageRecorders;
} } /**
* @return Returns the currentPage.
*/
public String getCurrentPage() {
return this.toString(currentPage);
}
/**
* @param currentPage The currentPage to set.
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
/**
* @return Returns the pageRecorders.
*/
public int getPageRecorders() {
return pageRecorders;
}
/**
* @param pageRecorders The pageRecorders to set.
*/
public void setPageRecorders(int pageRecorders) {
this.pageRecorders = pageRecorders;
}
/**
* @return Returns the pageEndRow.
*/
public int getPageEndRow() {
return pageEndRow;
}
/**
* @return Returns the pageStartRow.
*/
public int getPageStartRow() {
return pageStartRow;
}
/**
* @return Returns the totalPages.
*/
public String getTotalPages() { return this.toString(totalPages);
}
/**
* @return Returns the totalRows.
*/
public String getTotalRows() {
return this.toString(totalRows);
}
/**
* @return Returns the hasNextPage.
*/
public boolean isHasNextPage() {
return hasNextPage;
}
/**
* @param hasNextPage The hasNextPage to set.
*/
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
/**
* @return Returns the hasPreviousPage.
*/
public boolean isHasPreviousPage() {
return hasPreviousPage;
}
/**
* @param hasPreviousPage The hasPreviousPage to set.
*/
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public Team[] getNextPage(){
System.out.println("1----------currentPage----------"+currentPage);
currentPage=currentPage+1; //就是在这里,它每次好像都是默认为1了,为什么不变呢,要是可以,就先拿到自己的机器上试一试吧
System.out.println("2----------currentPage----------"+currentPage);
System.out.println("PageBean.getNextPage()正在执行;");
System.out.println("参数currentPage="+currentPage); if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
System.out.println("参数hasNextPage="+hasNextPage);
System.out.println("准备执行PageBean.getBooks()");
Team[] ProductionVos=getProductionVos();
this.description(); return ProductionVos;
} public Team[] getPreviouspage(){ currentPage=currentPage-1; if(currentPage==0){currentPage=1;} if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
Team[] pro=getProductionVos();
this.description();
return pro;
} public Team[] getProductionVos(){
System.out.println("pageBean.getProductionVos()开始执行;");
System.out.println("当前页:"+currentPage);
if(currentPage*pageRecorders<totalRows){//判断是否为最后一页
pageEndRow=currentPage*pageRecorders;
pageStartRow=pageEndRow-pageRecorders;
}
else{
pageEndRow=totalRows;
pageStartRow=pageRecorders*(totalPages-1);
}
Team[] ProductionVos=new Team[pageEndRow-pageStartRow+1]; System.out.println("pageStartRow="+pageStartRow);
System.out.println("pageEndRow="+pageEndRow);
int j=0;
for(int i=pageStartRow;i<pageEndRow;i++)
{ Team ProductionVo=(Team)arrayList.get(i);
ProductionVos[j++]=ProductionVo; }
System.out.println("要显示的页面数据已经封装,具体信息如下:");
this.description();
return ProductionVos;
} public String toString(int temp)
{
String str=Integer.toString(temp);
return str;
} public void description()
{ String description="共有数据数:"+this.getTotalRows()+ "共有页数: "+this.getTotalPages() + "当前页数为:"+this.getCurrentPage()+ " 是否有前一页: "+this.isHasPreviousPage() + " 是否有下一页:"+this.isHasNextPage()+ " 开始行数:"+this.getPageStartRow()+ " 终止行数:"+this.getPageEndRow(); System.out.println(description); }
}
解决方案 »
- String 如何替换 指定位置的字符串???
- TPS(旅行家)问题,自己随便谢谢,高手进来看一下对不对。
- 程序源代码相似度匹配算法
- readObject时 java.io.StreamCorruptedException: invalid type code: 6A?有时候却又没问题。
- 请教一段简单代码,关于调用frame的
- 如何将编译好的class文件打包成可执行的jar文件??
- 接 java applet 送给女朋友帖 正式启动 核心成员招募中
- 在APPLET怎么弹出对话框!
- 汉洛塔问题求解程序,错在哪里啊?
- Graphics 的 drawImage() 为什么有时画不出来?
- 非常菜鸟的问题!
- JAVA中怎么实现javascript的setTimeout功能
public class TeamAction extends DispatchAction {
/*
* Generated Methods
*/
TeamPage pb;
TeamDao teamDao = new TeamDao();
public ActionForward teamList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<Team> list = teamDao.teamList();
String action = request.getParameter("action");
System.out.println("===================================================取到参数action的值==="+action);
if( action == null || action.equals(null) ){
pb = new TeamPage(list);
Team[] teams = pb.getProductionVos();
pb.description();
request.setAttribute("list", teams);
request.setAttribute("page", pb);
}else{
if(action=="nextPage" || action.equals("nextPage")){
System.out.println("函数pb.getNextPage()准备执行");
pb = new TeamPage(list);
Team[] teams = pb.getNextPage();
request.setAttribute("page",pb);
request.setAttribute("list",teams);
}
if(action=="previousPage" || action.equals("previousPage")){
System.out.println("参数action="+action);
System.out.println("函数pb.getPreviouspage()准备执行");
pb = new TeamPage(list);
Team[] teams=pb.getPreviouspage();
request.setAttribute("page",pb);
request.setAttribute("list",teams);
}
}
//request.setAttribute("list", list);
return mapping.findForward("teamList");
}
下面是JSP页面代码:
<%@ page language="java" pageEncoding="GBK"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>team.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body> <table border="1" align="center">
<tr>
<td>teamId </td>
<td>teamName </td>
<td>teamLocal </td>
<td> 查看</td>
</tr>
<logic:present name="list" scope="request" >
<logic:iterate name="list" id="team">
<logic:present name="team" >
<tr>
<td><bean:write name="team" property="teamId" /> </td>
<td><bean:write name="team" property="teamName" /> </td>
<td><bean:write name="team" property="teamLocal" /> </td>
<td><html:link action="team.do?method=view" paramId="teamId" paramName="team" paramProperty="teamId" >查看</html:link> </td>
</tr>
</logic:present>
</logic:iterate>
</logic:present>
</table>
<br>
<center>
<logic:equal name="page" property="hasPreviousPage" value="true">
<html:link page="/team.do?method=teamList&action=previousPage">上一页</html:link>
</logic:equal>
<logic:equal name="page" property="hasNextPage" value="true">
<html:link page="/team.do?method=teamList&action=nextPage">下一页</html:link>
</logic:equal> <br><br><font size="2">
共有数据总数<font color="red"><strong><bean:write name="page" property="totalRows"/></strong></font>条
共分<font color="red"><strong><bean:write name="page" property="totalPages"/></strong></font>页
当前是第<font color="red"><strong><bean:write name="page" property="currentPage"/></strong></font>页</font>
</center>
<html:link action="team.do?method=add" >添加</html:link>
<html:form action="team.do?method=find">
<html:text property="teamName" value=""></html:text><html:submit></html:submit>
</html:form>
</body>
</html:html>