此页名﹕PUBFAczshow.jsp
上页傳入參數﹕lsh
<%
       Connection conn;
       DBConnection db = new DBConnection("ce.dbcon.dbConfig");
       Statement stmt = null;
       ResultSet rs = null;
       String sql;
         
       int pageSize;
       int rowCount; 
       int pageCount; 
       int i,j; 
       pageSize = 10;
       int intPage; 
       String strPage = request.getParameter("page"); 
       if(strPage==null)
       {
           intPage =1;
       }
       else
       {
           intPage = Integer.parseInt(strPage);
           if(intPage<1)
               intPage = 1;
       }
       String dqlsh = request.getParameter("lsh");
       conn = db.getConnection("ce.dbcon.dbConfig");
       stmt = conn.createStatement();
       sql = "select count(*) from PUBFA_CZ_TB where lsh='"+dqlsh+"'";
       rs = stmt.executeQuery(sql);
         
       rs.next(); 
         
       rowCount = rs.getInt(1);
       rs.close();
         
       pageCount = (rowCount+pageSize-1)/pageSize;
       sql ="select * from PUBFA_CZ_TB where lsh='"+dqlsh+"'";
       rs = stmt.executeQuery(sql);
       i = (intPage-1) * pageSize;
       for(j=0;j<i;j++) rs.next();
     %>
                   
        <table width="100%" align="center" border="1" cellpadding="0" cellspacing="0">
     <%
     i =0;
     while(i<pageSize&&rs.next())
     {
     %>
       <tr height="40">
     <%
       String gh = null;
       String xm = null;
       String kssj = null;
       String jssj = null;
       String kssjsub = null;
       String jssjsub = null;
       IUserInfo clr = null;
       if(rs != null)
       gh = rs.getString(2);
       kssj = rs.getString(4);
       jssj = rs.getString(5);
       IUserInfoDao userdao = new UserInfoDao();
       clr = userdao.findByGh(gh);
       if(clr != null)
          xm = clr.getXm();
          if(kssj != null)
          kssjsub = kssj.substring(0,16);
          if(jssj != null)
          jssjsub = jssj.substring(0,16);
     %>
     <%
         out.print("<td bgcolor=#ffff99>"+gh+"</td>");
         out.print("<td bgcolor=#66ff99>"+xm+"</td>");
         out.print("<td bgcolor=#ffff99>"+rs.getString(3)+"</td>");
         out.print("<td bgcolor=#66ff99>"+kssjsub+"</td>");
         out.print("<td bgcolor=#ffff99>"+jssjsub+"</td>");
         out.print("<td bgcolor=#66ff99>"+rs.getString(6)+"</td>");
         out.print("<td bgcolor=#ffff99>"+rs.getString(7)+"</td>");
       %>
       <%
       i++;
     }
     %>
       </tr>         
       <tr height="40">
         <td colspan=7 align="center">
           第<%=intPage%>页   共<%=pageCount%>页
         <%
           if(intPage>1)
           {
         %>
           <a href="PUBFAczshow.jsp?page=<%=intPage-1%>">上一页</a>
         <%
           }
         %>
         <%
           if(intPage<pageCount)
           {
         %>
           <a href="PUBFAczshow.jsp?page=<%=intPage+1%>">下一页</a>
         <%
           }
         %>
         </td>
       </tr>
     </table>
     <%
       rs.close();
       stmt.close(); 
       db.closeConnection();
     %>

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【aihua_z】截止到2008-07-22 10:30:26的历史汇总数据(不包括此帖):
    发帖的总数量:9                        发帖的总分数:270                      每贴平均分数:30                       
    回帖的总数量:15                       得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:8                        结贴的总分数:240                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:30                       
    结贴的百分比:88.89 %               结分的百分比:88.89 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    我没有看的太仔细,
    你说上页传入的参数只有lsh,
    那你那个String strPage = request.getParameter("page"); 
    “page”从哪来?
      

  3.   

    page= <%=intPage-1%>
    page= <%=intPage+1%>我這個分页﹐在沒有 上页傳入參數 的時候是正確的﹐有了這個條件后﹐跳轉就有問題了
      

  4.   

         int intPage; 改为       int intPage = 1试试 
      

  5.   

    建议,建一个Page.java,用于存放你分页的那些参数。
      

  6.   

    <a href="PUBFAczshow.jsp?page= <%=intPage-1%>">上一页 </a> 
    <a href="PUBFAczshow.jsp?page= <%=intPage+1%>">下一页 </a> 是不是這里有錯誤呢?我有參數傳過來的﹐而這里就有點不對了
      

  7.   

    <% 
          Connection conn; 
          DBConnection db = new DBConnection("ce.dbcon.dbConfig"); 
          Statement stmt = null; 
          ResultSet rs = null; 
          String sql; 
            
          int pageSize; 
          int rowCount; 
          int pageCount; 
          int i,j; 
          pageSize = 10; 
          int intPage; 
    ***      String strPage = request.getParameter("page"); 
          if(strPage==null) 
          { 
              intPage =1; 
          } 
          else 
          { 
              intPage = Integer.parseInt(strPage); 
              if(intPage <1) 
                  intPage = 1; 
          } 
    ***      String dqlsh = request.getParameter("lsh"); 你太走运了,我刚刚做了这个分页处理,解决了这个问题,o(∩_∩)o...
    注意前面有***的两句代码,第一句是得到当前页码的,第二句是得到客户端输入的检索关键字的,没错吧!!
    这样的话当你第一次加载该页面的时候,能够得到参数“lsh”,request.getParameter("1sh")没有问题。
    但是当你点击上一页或下一页后,比如当前页是A,点击上一页后进入B,当然A.B其实是同一个页面,只不过页码不同了。
    此时在B中调用request.getParameter("参数名")时,参数名会从A中寻找,但是由A-->B时,你只设置了参数“page”而没有参数"1sh",代码::
     if(intPage>1) 
              { 
            %> 
              <a href="PUBFAczshow.jsp?page= <%=intPage-1%>">上一页 </a> 
            <% 
              } 
            %> 
            <% 
              if(intPage <pageCount) 
              { 
            %> 
              <a href="PUBFAczshow.jsp?page= <%=intPage+1%>">下一页 </a> 
            <% 
              } 所以request.getParamter("1sh")因找不到而出现异常。解决办法::
    将以上代码改为:
    if(intPage>1) 
              { 
            %> 
              <a href="PUBFAczshow.jsp?page= <%=intPage-1%>&lsh=<%=dqlsh%>">上一页 </a> 
            <% 
              } 
            %> 
            <% 
              if(intPage <pageCount) 
              { 
            %> 
              <a href="PUBFAczshow.jsp?page= <%=intPage+1%>&lsh=<%dqlsh%>">下一页 </a> 
            <% 
              } 你先试一下,不行再说!!
      

  8.   

    12楼正解
    不过还有一处错误,不改的话会报数据类型转换错误
    就是page= <%=intPage+1%>
    page=后面不能有空格,否则intPage = Integer.parseInt(strPage);会报错(因为strPage前面有个空格)
      

  9.   

    搞定了﹐非常感謝﹗其實當初我也想到了﹐可惜代碼寫錯了﹕
    <a href="PUBFAczshow.jsp?page= <%=intPage-1%>?lsh= <%=dqlsh%>">上一页 </a> 
    <a href="PUBFAczshow.jsp?page= <%=intPage+1%>?lsh= <%dqlsh%>">下一页 </a>