jsp 分頁程式碼

來源:互聯網
上載者:User

jsp 分頁程式碼

<%
 String s;
 String theurl;
 theurl="products.jsp?";
 s=request.getParameter("s");
 if(s!=null){
  s=new String(request.getParameter("s").getBytes("iso-8859-1"));
  theurl="products.jsp?s="+s;
 }
 Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
 ResultSet Rs=stmt.executeQuery("Select * from hl_smallclass WHERE modiname='產品'");
 while (Rs.next()) {
 String smallname = Rs.getString("smallname");
%>
      <tr>
        <td height="32" align="center" style="background:url(images/ntb_bg.jpg) no-repeat center"><a href='products.jsp?modi=產品&b=<%=Rs.getString("bigname")%>&s=<%=smallname%>'>::<%=smallname%>::</a></td>
      </tr>
<%
}
 Rs.close();
%>
    </table>
 </td>
    <td width="687" rowspan="2" align="center" valign="top" bgcolor="#FFFFFF" style="background:#fff url(images/main_bg.jpg) repeat-x top;"><table style="margin-top:5px;" width="98%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="4%" height="30" align="center" style="border-bottom:#ebebeb 1px solid"><img src="images/san.gif" width="8" height="11" /></td>
        <td width="96%" align="left" style="border-bottom:#ebebeb 1px solid"><a href="index.jsp">首頁</a> &gt; <a href="products.jsp">產品展示</a> &gt; <%  if(s!=null){ out.print(s); } %></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><table width="95%" border="0" cellpadding="0" cellspacing="0"  style=" border-bottom:#E7E7E7 1px solid;margin-top:15px;">
          <tr>
            <td height="22" align="center">以下為我公司<% if(s!=null){ out.print(s); } if(s==null){    %>所有<% }%>產品;點擊相應的圖片或文字進入查看詳細產品資訊</td>
          </tr>
        </table>
          <table style="margin-top:5px;" width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center" valign="top">
   
   
   <table style="margin-top:8px;" width="96%" border="0" cellspacing="0" cellpadding="0">
       <tr>
<%
int pageSize=9;
int showPage=1;
int recCount=0;
int t=0;
int pageCount=0;
String toPage = request.getParameter("page");
String sqlp;
  sqlp="Select * from hl_product order by ID desc";
 if(s!=null){
  sqlp="Select * from hl_product WHERE smallname='"+s+"'";
 }
 ResultSet RsA=stmt.executeQuery(sqlp);
if(RsA.next()) { 
 RsA.last();
 recCount=RsA.getRow();
 pageCount=((recCount%pageSize)==0?(recCount/pageSize):(recCount/pageSize)+1);
 if(toPage!=null)
  showPage=Integer.parseInt(toPage);
  RsA.absolute((showPage-1)*pageSize+1);
 for(int i=1;i<=pageSize;i++){
 String ttt = RsA.getString("title");
 //ttt=ttt.substring(0,10);
 int ID=RsA.getInt("ID");
%>
   <TD align="left">
    <table style="margin-top:15px;" width="143" height="125" border="0" cellpadding="0" cellspacing="0" bgcolor="#F5F5F5">
                      <tr>
                        <td height="104" align="center"><table width="138" border="0" cellpadding="0" cellspacing="0" class="k_a_1">
                            <tr>
                              <td height="96" align="center" bgcolor="#FFFFFF"><a target="_blank" href="proshow.jsp?id=<%=ID%>"><img src="<%=RsA.getString("img")%>" alt="" width="190" height="120" border="0" onerror="javascript:this.src='images/nopic.gif'"/></a></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td height="26" align="center" class="f-12-black"><a target="_blank" href="proshow.jsp?id=<%=ID%>"><%=RsA.getString("title")%></a></td>
                      </tr>
                  </table>
  </td>
                         
<% 
 t++;
 if (i%3==0)  out.print("</tr><tr>");

 if(!RsA.next())
  break;
 }

}
 RsA.close();
%>

   <tr>
            </table>


 
              <table align="center">
                <form
                          action="news.asp?classid=&amp;bigclassname=新聞線上"
                          method="post" name="showpages" id="showpages">
                  <tbody>
                    <tr>
                      <td><% if(showPage>1){ %><a class='f-12-black' href='<%=theurl%>&page=1'>首頁</a> <% } if (showPage>1) { %><a class='f-12-black' href='<%=theurl%>&page=<%= showPage-1 %>'>上一頁</a>&nbsp;<% } if (showPage<pageCount) { %>&nbsp;<a class='f-12-black' href='<%=theurl%>&page=<%= showPage+1 %>'>下一頁</a>&nbsp;<% } %>&nbsp;<% if(showPage<pageCount){ %><a class='f-12-black' href='<%=theurl%>&page=<%=pageCount %>'>尾頁</a>&nbsp;<%       } %> 頁次:<%=showPage %>/<%=pageCount%>頁 共有<%=recCount%>條記錄 <a class='f-12-black'>轉到第<select name='sel_page' onChange='javascript:location=this.options[this.selectedIndex].value;'><%  for(int i=1;i<=pageCount;i++){  %> <option value='<%=theurl%>&page=<%=i %>' <% if(i==showPage){ %>selected <% } %>><%=i %></option><% } %></select>頁</a></td>
                    </tr>
                  </tbody>
                </form>
                <tr>
                  <td></TBODY></td>
                </tr>
              </table>
              <br /></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td width="42" rowspan="3" style="background:url(images/rightbg.jpg) repeat-y left">&nbsp;</td>
  </tr>
</table>
<%
stmt.close();
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.