这是Dao层的代码
一个是分页查询
一个是查询一共多少条记录package Dao; 
import java.util.ArrayList;
import java.util.List; 
import Entry.BookInfo;
public class BookInfoDaoImpl extends BaseDao implements BookInfoDao { 
public List<BookInfo> showAllBook(int page,int pageIndex) {
openConnection();
List<BookInfo> bookInfoList=new ArrayList<BookInfo>();
String sqlString="select top "+page+" * from bookinfo where bookid not in(select top (("+pageIndex+"-1)*"+page+") bookid from bookinfo)";
try {
stmt=conn.prepareStatement(sqlString);
rs=stmt.executeQuery();
while (rs.next()) {
BookInfo bookInfo=new BookInfo();
bookInfo.setId(rs.getString("bookid"));
bookInfo.setBookName(rs.getString("bookname"));
bookInfo.setBookType(rs.getString("booktype"));
bookInfo.setBookStatus(rs.getString("bookstatus"));
bookInfoList.add(bookInfo);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
closeAll();
}
return bookInfoList;

public int bookInfoCount() {
openConnection();
String sqlString="select count(*) from bookinfo";
int i=0;
try {
stmt=conn.prepareStatement(sqlString);
rs=stmt.executeQuery();
if(rs.next()){
i=rs.getInt(1);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
closeAll();
}
return i;

}
---------------------------------------------------------------------------------------
下面是JSP页面的内容
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@page import="Biz.BookInfoBiz"%>
<%@page import="Biz.BookInfoBizImpl"%>
<%@page import="Entry.BookInfo"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</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">
<tr>
<td>图书名称</td>
<td>类别</td>
<td>状态</td>
</tr>
<%
BookInfoBiz bb=new BookInfoBizImpl();
int book_count=bb.bookInfoCount();
int page_size=5;
int page_count=book_count%page_size==0?book_count/page_size:book_count/page_size+1;
int pageIndex=1;
String pageIndex_str=(String)request.getAttribute("pageIndex");
if(pageIndex_str!=null){
pageIndex=Integer.valueOf(pageIndex_str); 
}
List<BookInfo> bookinfoList=bb.showAllBook(page_size,pageIndex); 
for(int i=0;i<bookinfoList.size();i++){
BookInfo bookinfo=bookinfoList.get(i);
%>
<tr>
<td><%=bookinfo.getBookName() %></td>
<td><%=bookinfo.getBookType() %></td>
<td><%=bookinfo.getBookStatus() %></td>
</tr>
<%
}
%>
<p><a href="index.jsp?pageIndex=<%=pageIndex-1 %>">上一页</a><a href="index.jsp?pageIndex=<%=pageIndex+1 %>">下一页</a></p>
</table>
</body>
</html>各位帮忙看看那里错了。上一页和下一页都不好使 

解决方案 »

  1.   

    错误的结果是?
    什么显示都没?
    包错了?
    你的SQL语句贴全了?
      

  2.   

    http://zhidao.baidu.com/question/116317819.htmljsp分页例子很多,楼主就细找找代码的问题,看是数据的问题,还是按钮没有响应,还是配置错了。
      

  3.   

    BookInfoBiz bb=new BookInfoBizImpl();
    这句话不报错?有这个类吗?
    我也是这么写的,附上代码:跟你的思路是一样的if (request.getParameter("review_state") != null || request.getParameter("page") != null) {
    int pagecount = 20; //一页显示的记录数 
    int rowcount = 0; //记录总数 
    int sumpagecount = 0; //总页数 
    int currentPage = 1; //待显示页码  //取得待显示页码 
    String strPage = request.getParameter("page");
    if (strPage == null) {
    //表明在QueryString中没有page这一个参数,此时显示第一页数据 
    currentPage = 1;
    } else {
    //将字符串转换成整型 
    currentPage = Integer.parseInt(strPage);
    if (currentPage < 1)
    currentPage = 1;
    }                   //获取记录总数 
    paging sum = new paging();
    rowcount = sum.sumpage(sqlcond);
    //记算总页数
    sumpagecount = sum.sumpagecount(pagecount, sqlcond);
    //调整待显示的页码 
    if (sumpagecount == 0)
    sumpagecount++;
    if (currentPage > sumpagecount)
    currentPage = sumpagecount; List<Member> memberlist = sum.fenye(currentPage, pagecount,
    sqlcond);
    System.out.println("currentPage" + currentPage);
    System.out.println("pagecount" + pagecount); request.setAttribute("member", memberlist);
      

  4.   

    确实有些蛋疼!
    给个demo,要么?