给你一个例子:<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page language="java" %>
<%@ page import="Common.*" %><jsp:useBean id="checkdata" class="Common.CheckData" scope="page" /><jsp:useBean id="user" class="Simis.User" scope="session" />
<jsp:useBean id="arraytable" class="Common.ArrayTable" scope="page" />
<%
 if ((!user.isLogin())||(Integer.valueOf(user.getRight()).intValue()!=1)) {
%>
  <jsp:include page="index.jsp" flush="true" />
<%}else{%><%!
int PageSize = 1; //设置每张网页显示两笔记录
int ShowPage = 1; //设置欲显示的页数
int RowCount = 0; //ResultSet的记录笔数
int PageCount = 0; //ResultSet分页后的总页数
CodeTable codeTable = null;
String strSQL = "select distinct * from sinetac01,sinetac02 where sinetac01.personflow=sinetac02.personflow AND sinetac01.checkflag='0' ";String str = null;
ResultSet rs = null;
DBSQL db = new DBSQL();
DBConnectionManager dbcm=new DBConnectionManager();
%><%
//取得查询条件
strSQL = "select  distinct * from sinetac01,sinetac02 where sinetac01.personflow=sinetac02.personflow AND sinetac01.checkflag='0' ";
if(str == null && request.getParameter("unname") == null)
{
     str = "";
     strSQL = "select distinct * from sinetac01,sinetac02 where sinetac01.personflow=sinetac02.personflow AND sinetac01.checkflag='0' ";
}
else if(request.getParameter("unname")!= null)
{     if(!str.equals(request.getParameter("unname")))
     {
        str = request.getParameter("unname");
        strSQL += "AND sinetac01.aab001= '" + str + "' ";
     }
     else if(str.equals(request.getParameter("unname")) && str == "")
          strSQL = "select distinct * from sinetac01,sinetac02 where sinetac01.personflow= sinetac02.personflow AND sinetac01.checkflag='0' ";
     else
     {
        strSQL = "select distinct * from sinetac01,sinetac02 where sinetac01.personflow= sinetac02.personflow AND sinetac01.checkflag='0' ";
        strSQL += "AND sinetac01.aab001= '" + str + "' ";
     }
 }
 else
 {
     str = "";
     strSQL = "select distinct * from sinetac01,sinetac02 where sinetac01.personflow= sinetac02.personflow AND sinetac01.checkflag='0' ";
  }try{
        strSQL += "order by sinetac02.netdeclaredate";
        db.openQueryDB();
        rs = db.executeQuery(strSQL);
        rs.last(); //将指标移至最后一笔记录
        RowCount = rs.getRow(); //取得ResultSet中记录的笔数
//计算显示的页数
PageCount = ((RowCount % PageSize) == 0 ?
(RowCount/PageSize) : (RowCount/PageSize)+1);
        codeTable = dbcm.getCodeTable("soft");    }
    catch(Exception ex)
    {
System.out.println(ex.toString());
%><%}%>
<%
String ToPage = request.getParameter("ToPage");
if(ToPage != null) //判断是否可正确取得ToPage参数
{
ShowPage = Integer.parseInt(ToPage);  //取得指定显示的分页页数
if(ShowPage > PageCount)  //下面的if语句将判断用户输入的页数是否正确
{
ShowPage = PageCount;  //判断指定页数是否大于总页数, 是则设置显示最后一页
}
else if(ShowPage <= 0)
{
ShowPage = 1;  //若指定页数小于0, 则设置显示第一页的记录
}
}
if(ShowPage >0)
   rs.absolute((ShowPage - 1) * PageSize + 1);  //计算欲显示页的第一笔记录位置
%><script>
function YearNull() {
  thisform.unname.value="";
}
function YearNull1() {
  if(document.thisform.unname.value == "")
  {
    alert("请输入查询单位编号");
    document.thisform.unname.focus();
  }
  else
  {
     document.thisform.action="exam_new.jsp?ToPage=1";
     document.thisform.submit();
  }
}function keydown()
{
   var whichkey = event.keyCode;
   if (whichkey == 13||whichkey == 10)
   {
       if(document.thisform.ToPage.value == "")
       {
         document.thisform.ToPage.focus();
         return;
       }
       else
         document.thisform.submit();
   }
}
function keydown1()
{
   var whichkey = event.keyCode;
   if (whichkey == 13||whichkey == 10)
   {
       document.thisform.action="exam_new.jsp?ToPage=1";
       document.thisform.submit();
   }
}
function PageDown()
{
    document.thisform.action = "exam_new.jsp?ToPage="+"<%= ShowPage + 1 %>";
    document.thisform.submit();}
function PageUp()
{
    document.thisform.action = "exam_new.jsp?ToPage="+"<%= ShowPage - 1 %>";
    document.thisform.submit();}
function PageFirst()
{
    document.thisform.action = "exam_new.jsp?ToPage="+"<%= 1 %>";
    document.thisform.submit();
}
function PageLast()
{
    document.thisform.action = "exam_new.jsp?ToPage="+"<%= PageCount %>";
    document.thisform.submit();
}
</script><html>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<div align="center" >
<jsp:include page="head.jsp" flush="true" />
<jsp:include page="exam_title.jsp" flush="true" /><td width="736" bgcolor="#FFFFFF" height="22"><p align="center"><font face="楷体_GB2312" size="5" color="#000000"><strong>新参保查询结果</strong></font></p></td>
<form name="thisform" method="post" action="exam_new.jsp"  >
<table>
<tr ><td width="80"  height="26" align="left"><font face="楷体_GB2312" size="3" color="#000000"><B>单位编号</B></font></td>
    <td width="18%" height="26" align="left">
        <input name="unname" type="text" length="8" value="<%=str%>" onkeydown="keydown1();">
    </td>
    <td width="538" height="26" align="left">
    <input type="button" value="查询"  onClick="YearNull1();" id="SubData" name="SubData">
    <input type="button" value="重添"  onClick="YearNull();" name="button2">
    </td>
</tr>
</table><%
//利用For循环配合PageSize属性输出一页中的记录
System.out.println("===========>1");
if(RowCount > 0)
{%>
 <td width="736" bgcolor="#DFDFDF" height="22"><p align="center"><font face="楷体_GB2312" size="4" color="#000000"><strong>职工待审查询第<%  out.print(ShowPage); %>页, 共<%  out.print(PageCount); %>页</strong></font></p></td>
<%
System.out.println("===========>2");
for(int i = 1; i <= PageSize; i++)
{
System.out.println("===========>3");
%>

解决方案 »

  1.   

    具体思想是这样的。 先取得你要查询的数据一共有多少条。
    就是代码里
            rs.last(); 
            RowCount = rs.getRow(); 
    这二句话。
    然后根据你要每页显示的条数,和当前是第几页,算出本页应该从第几条显示到第几条。
    因为总的记录数是已知的,所以总的页数也就是能算出来。如果请求显示的页数超过了总页数,或小于1,那就显示最后一页,或第一页。大致的思想就是这样。
    我想你问 有没有 rs.last(); 这个方法,可能你是用了,但没成功,那是因为你打开数据集的时候没有加参数,你的数据集只能向前一条一条的移动。如果你要使用 last()等方法,你要在打开数据集的时候加上:      
    pst=con.prepareStatement("SQL",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    这样就可以了