<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<%
int p =1;
if(request.getParameter("p")!=null)
{
p=Integer.parseInt(request.getParameter("p"));
}
Operator o =new Operator();
List list =o.getBookList(p,3);
%>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="441" height="63" border="1">
<tr>
<td>图书名称</td>
<td>图书类型</td>
<td>是否借阅</td>
</tr>
<%
for(int i=0;i<list.size();i++)
{
bookInfo b =(bookInfo)list.get(i);
%>
<tr>
<td><%= b.getBookName() %></td>
<td><%= b.getBookType() %></td>
<td><%= b.getBookStatus() %></td>
</tr>
<%} %>
<a href="infoList.jsp?p=<%=p-1 %>">上一页</a><a href="infoList.jsp?p=<%=p+1 %>">下一页</a>
</table>
</form>
</body>
</html>
这是一段翻页的代码,可是翻到最后一页 再点下一页的话 它还是会继续往下翻 显示的就是空内容
求高手赐教
我该怎么添加条件 让他停止翻页
下一页
}else{
<a href="infoList.jsp?p=<%=p+1 %>">下一页</a>
}
共${entity.count }条数据
当前在第${entity.pageNum }页
分${entity.pageAll }页显示
<%
if(entity.getPageNum()==1||entity.getPageNum()==0){
%>
首页
上一页
<%} else{%>
<A href="xx.jsp??page=1">首页</A >
<a href="xx.jsp?page=${entity.pageNum-1 }">上一页</a><%}
if(entity.getPageNum()==entity.getPageAll()){
%> 下一页 未页 <%}else{ %>
<a href="xx.jsp??page=${entity.pageNum+1 }">下一页</a>
<a href="xx.jsp??page=${entity.pageAll }">未页 </a>
<%} %>
<input type="text" name=page id= page style="width: 30px;" onkeyup="carCount (this)" />
<input type="submit" class=button value=go style="height: 20px;" />
</form>
sql 自己写了
2 还是你的程序有问题的~ 要对当前显示页数进行判断package com.common;import org.apache.struts2.ServletActionContext;public class PageBean {
public int getPageSize(){
return 15;
}
/**
* 数字分页
* */
public void getNumberPage(int pageCount,String fy,int showPage){
int fyShowPage = 1;
int fyPageSize = 10;
int fyTotalCount = pageCount;
int fyPageCount = fyTotalCount % fyPageSize==0 ? fyTotalCount/fyPageSize : fyTotalCount/fyPageSize + 1;
int fyPosition = 0;
if(fy!=null){
fyShowPage = Integer.parseInt(fy);
}
if(fyShowPage < 1){
fyShowPage = 1;
}
if(fyShowPage > fyPageCount){
fyShowPage = fyPageCount;
}
fyPosition = (fyShowPage-1)*fyPageSize+1;
if(showPage == fyPosition+fyPageSize){
fyShowPage = fyShowPage + 1;
}
if(showPage == fyPosition-1){
fyShowPage = fyShowPage - 1;
}
if(fyShowPage < 1){
fyShowPage = 1;
}
if(fyShowPage > fyPageCount){
fyShowPage = fyPageCount;
}
fyPosition = (fyShowPage-1)*fyPageSize+1;
ServletActionContext.getContext().put("fyShowPage",fyShowPage);
ServletActionContext.getContext().put("fyPageSize",fyPageSize);
ServletActionContext.getContext().put("fyPageCount", fyPageCount);
ServletActionContext.getContext().put("fyPosition", fyPosition);
}
/**
* 计算得到总页数
* */
public int getPageCount(int totalCount,int pageSize){
return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
}
/**
* 当前页
* */
public int getShowPage(String sp,int pageCount){
int showPage = 1;
if(null!=sp && sp.trim().length()>0){
try{
showPage = Integer.parseInt(sp);
}catch(NumberFormatException nfe){
showPage = 1;
}
}
if(showPage<1){
showPage = 1;
}
if(showPage>pageCount){
showPage = pageCount;
}
return showPage;
}
}
希望可以帮到你!
2 对当前页进行判断 代码如下package com.common;import org.apache.struts2.ServletActionContext;public class PageBean {
public int getPageSize(){
return 15;
}
/**
* 数字分页
* */
public void getNumberPage(int pageCount,String fy,int showPage){
int fyShowPage = 1;
int fyPageSize = 10;
int fyTotalCount = pageCount;
int fyPageCount = fyTotalCount % fyPageSize==0 ? fyTotalCount/fyPageSize : fyTotalCount/fyPageSize + 1;
int fyPosition = 0;
if(fy!=null){
fyShowPage = Integer.parseInt(fy);
}
if(fyShowPage < 1){
fyShowPage = 1;
}
if(fyShowPage > fyPageCount){
fyShowPage = fyPageCount;
}
fyPosition = (fyShowPage-1)*fyPageSize+1;
if(showPage == fyPosition+fyPageSize){
fyShowPage = fyShowPage + 1;
}
if(showPage == fyPosition-1){
fyShowPage = fyShowPage - 1;
}
if(fyShowPage < 1){
fyShowPage = 1;
}
if(fyShowPage > fyPageCount){
fyShowPage = fyPageCount;
}
fyPosition = (fyShowPage-1)*fyPageSize+1;
ServletActionContext.getContext().put("fyShowPage",fyShowPage);
ServletActionContext.getContext().put("fyPageSize",fyPageSize);
ServletActionContext.getContext().put("fyPageCount", fyPageCount);
ServletActionContext.getContext().put("fyPosition", fyPosition);
}
/**
* 计算得到总页数
* */
public int getPageCount(int totalCount,int pageSize){
return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
}
/**
* 当前页
* */
public int getShowPage(String sp,int pageCount){
int showPage = 1;
if(null!=sp && sp.trim().length()>0){
try{
showPage = Integer.parseInt(sp);
}catch(NumberFormatException nfe){
showPage = 1;
}
}
if(showPage<1){
showPage = 1;
}
if(showPage>pageCount){
showPage = pageCount;
}
return showPage;
}
}
import java.sql.SQLException;import database.DBConn;public class ShowJckcPage {
int pagenow;
int pagecount;
int pagesize;
int rowcount; public ShowJckcPage()
{
pagenow = 1;
pagecount = 0;
pagesize = 15;
rowcount = 0;
} public int fpage(String spagenow)
{
ShowJckcPage pb = new ShowJckcPage();
int pagecount = pb.countpage();
if (spagenow != null)
{
pagenow = Integer.parseInt(spagenow);
if (pagenow > pagecount)
pagenow = pagecount;
}
else
{
pagenow = 1;
}
return pagenow;
} public int countpage()
{
DBConn db = new DBConn();
String sql = "select count(*) from 表名";
ResultSet rs = db.executeQuery(sql);
try
{
while (rs.next())
rowcount = rs.getInt(1);
}
catch (SQLException e)
{
e.printStackTrace();
}
if (rowcount % pagesize == 0)
pagecount = rowcount / pagesize;
else
pagecount = rowcount / pagesize + 1;
return pagecount;
} public int rowpage()
throws SQLException
{
DBConn db = new DBConn();
String sql = "select count(*) from 表名";
for (ResultSet rs = db.executeQuery(sql); rs.next();)
rowcount = rs.getInt(1); return rowcount;
}} String spage
now = request.getParameter("pagenow");
int pagesize = 15;//每页显示的记录
int pagenow = spage.fpage(spagenow);//希望显示第几页
int rowcount = spage.rowpage();//共有几条记录(查表获得)
int pagecount = spage.countpage();//共有几页(计算)按照我上面的例子 判断就可以这样写的:if(pagenow==pagecount){
下一页//不加链接说明是最后一页
}else{
<a href="a.jsp">下一页</a>
}