关于分页的一个问题:
在查询的时候我用的是模糊查询,第一页可以正常显示符合条件的共几条,第几条,上一页,下一页,
这时候问题来了,当点下一页的时候,记录就为空了。
但是,我在查询整张表的时候点上一页,下一页是正常显示出来的,如果没有整张表查询,而是通过参数
传递给模糊查询,使符合条件的存到rst中,取出时候点下一页,那么就为空了.
能问问这是怎么回事吗?
我怀疑使指针的问题.
期待能帮我解决的高手,先谢过 ~~~:)
下面是查询和处理页面的代码:
查询页面:
------------main_product_see.jsp--------------------------------------
<%@page language="java" contentType="text/html;charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-family: "??ì?";
font-size: 12px;
color: #333333;
}
body {
background-color: #CED7F7;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #FF0000;
}
.style1 {color: #333333}
-->
</style></head><body>
<table width="990" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="990" height="100"><form name="form3" method="post" action="product_see.jsp">
        <table width="702" border="1" bordercolor="#1087B9">
          <tr>
            <td width="648" align="center" valign="middle" bgcolor="#4397c5" class="style1">商品查询</td>
          </tr>
          <tr>
            <td align="left" valign="middle" bgcolor="#BDE2F1">管理快捷方式:<a href="admin_index.jsp" target="_parent">管理首页</a></td>
          </tr>
          <tr>
            <td align="center" valign="middle" bgcolor="#BDE2F1">按
                <select name="select4" id="select4">
                  <option> product_id</option>
                  <option>product_name</option>
                  <option>sort_id</option>
                  <option>product_pubdate</option>
                  <option>product_sale</option>
                </select>
                <input name="cha4" type="text" value="">
              查询</td>
          </tr>
          <tr>
            <td align="center" valign="middle" bgcolor="#BDE2F1">
              <input type="submit" name="cha4" value="查询"></td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>
---------------------------------product_see.jsp------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
  byte tempB[]=s.getBytes("ISO-8859-1");
  s=new String(tempB);
  return s;
}
catch(Exception e)
{
  return s;
}
}
%>
<%//接收客户端提交的数据
String sqlString=null;
String cha3=codeToString(request.getParameter("cha4"));
String select3=codeToString(request.getParameter("select4"));
%>
<%
  Connection sqlCon;
  Statement sqlStmt;
  ResultSet sqlRst;
  String strCon;
  String strSQL;
  int intPageSize;
  int intRowCount;
  int intPageCount;
  int intPage;
  String strPage;
  int i;
  intPageSize = 2;
  strPage = request.getParameter("page");
  if(strPage==null){
   intPage = 1;
}
  else{
   intPage = java.lang.Integer.parseInt(strPage);
   if(intPage<1) intPage = 1;
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection  conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=shopping","test","test");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
strSQL="select * from productinf where "+select3+" "+"like'%"+cha3+"%' order by product_id desc";
ResultSet rst=stmt.executeQuery(strSQL);
rst.last();
intRowCount = rst.getRow();
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>
test_see
</title>
</head>
<body bgcolor="#ffffff">
<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
  <th>product_id</th>
  <th>product_name</th>
   <th>sort_id</th>
   <th>product_unitprice</th>
   <th>product_stocks</th>
   <th>product_publisher</th>
   <th>product_pubdate</th>
   <th>product_inf</th>
   <th>product_sale</th>
</tr>
<%
if(intPageCount>0){
 rst.absolute((intPage-1) * intPageSize + 1);
  i = 0;
 while(i<intPageSize && !rst.isAfterLast()){
%>
<tr>
  <td><%=rst.getString(1)%></td>
  <td><%=rst.getString(2)%></td>
   <td><%=rst.getString(3)%></td>
   <td><%=rst.getString(4)%></td>
   <td><%=rst.getString(5)%></td>
   <td><%=rst.getString(6)%></td>
   <td><%=rst.getString(7)%></td>
   <td><%=rst.getString(8)%></td>
   <td><%=rst.getString(9)%></td></tr>
<%
rst.next();
i++;
 }
}
%>
</table>
</table>第<%=intPage%>页  共<%=intPageCount%>页  <%if(intPage<intPageCount){%><a href="product_see.jsp?page=<%=intPage+1%>">下一页</a><%}%>  <%if(intPage>1){%><a href="product_see.jsp?page=<%=intPage-1%>">上一页</a><%}%>
</body>
</html>
<%
rst.close();
stmt.close();
conn.close();
%>

解决方案 »

  1.   

    因为你往下一页传的参数只有page,没有你的查询条件,所以查不出结果啊,你点上一页,也是一样的,只是把页数传过去了。你应该在?page=...后面再加上你其他的查询条件,也就是page=...&xxx=...&...
      

  2.   

    是的啊,点击下一页,要把你需要的参数都传递过去
    比如
    <a href="MeetingInfoQuery.jsp?page=<%=intPage-1%>&a=<%=queryString1%>&b=<%=queryString2%>&flag=<%=flag%>">上一页></a>>
      

  3.   

    各位对我的启发很大啊,可是我传了其他的总页数,还有strSQL等还是出现这问题。
    可能是我传的有误吧~~
    能针对,我的这些代码具体点吗?
    期待中:)
      

  4.   

    老大,你是不是链接写错了啊,我想你是想跳转到本页面吧,如果这样的话,结果集也用不着传了,
    每次进来的时候都会重新从数据库检索,你的链接href="product_see.jsp?page=<%=intPage+1%>"> 链接的目标jsp好象是main_product_see.jsp吧,如果是的话上面的连接可不就写错了
    ,你的程序我还真看不出有什么其它的错误了,可能是我太菜了吧!!!
      

  5.   

    SQL SERVER应该支持TOP吧~
    你可以使用TOP N * 来取数据,然后根据页面POST的CURPAGE_NO,来处理得到每次查询的开始记录SEQ和结束记录SEQ,然后在循环取数据的时候,根据一个ICOUNT来取出需要的数据..