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> > <a href="products.jsp">產品展示</a> > <% 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=&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> <% } if (showPage<pageCount) { %> <a class='f-12-black' href='<%=theurl%>&page=<%= showPage+1 %>'>下一頁</a> <% } %> <% if(showPage<pageCount){ %><a class='f-12-black' href='<%=theurl%>&page=<%=pageCount %>'>尾頁</a> <% } %> 頁次:<%=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"> </td>
</tr>
</table>
<%
stmt.close();
%>