jsp 簡單一實例分頁代碼
<%
int pageSize=10;
int showPage=1;
int recCount=0;
int pageCount=0;
String SqlArticle;
String toPage = request.getParameter("page");
SqlArticle="Select * from hl_news where smallname='"+csmallname+"' order by
times DESC";
ResultSet RsArticle=stmt1.executeQuery(SqlArticle);
if(RsArticle.next()) {
RsArticle.last();
recCount=RsArticle.getRow();
pageCount=((recCount%pageSize)==0?(recCount/pageSize):
(recCount/pageSize)+1);
if(toPage!=null)
showPage=Integer.parseInt(toPage);
RsArticle.absolute((showPage-1)*pageSize+1);
for(int i=1;i<=pageSize;i++){
int NID=RsArticle.getInt("ID");
String ttt = RsArticle.getString("times");
%>
<tr>
<td align="middle" width="18"><img height="5"
src="images/kuang_10.gif" width="5" /></td>
<td class="riqi_1" align="middle"
width="92"><span class="f-14-hui" style="width:100px;"><%=ttt%> |
</span></td>
<td width="463" height="30" align="left"
class="tong_1"><a class="wen_4" href="newshows.jsp?id=<%=NID%>"
target="_blank"><%=RsArticle.getString("title")%></a></td>
<td width="56" class="wen_4">[<a
href="newshows.jsp?id=<%=NID%>" target="_blank">查看</a>]</td>
</tr>
<tr>
<td background="images/kuang_09.gif" colspan="4"
height="2"></td>
</tr>
<%
if(!RsArticle.next())
break;
}
}
%>
</tbody>
</table></td>
<td width="4"
background="images/kuang_05.gif"></td>
</tr>
<tr>
<td width="4" height="4"><img height="4"
src="images/kuang_06.gif"
width="4" /></td>
<td background="images/kuang_07.gif"
height="4"></td>
<td width="4" height="4"><img height="4"
src="images/kuang_08.gif"
width="4" /></td>
</tr>
</tbody>
</table>
<table align="center" border="0">
<form onsubmit="document.location =
'http://www.intgz.com/news.asp?cid=1&Page='+ this.page.value;return
false;" method="get">
<tbody>
<tr>
<td align="right"> <% if(showPage>1){ %><a class='f
-12-black' href='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&page=1'>首
頁</a> <% } if (showPage>1) { %><a class='f-12-black' href='news.jsp?id=<%
=cid %>&smallname=<%=csmallname%>&page=<%= showPage-1 %>'>上一頁</a> <%
} if (showPage<pageCount) { %> <a class='f-12-black' href='news.jsp?
id=<%=cid %>&smallname=<%=csmallname%>&page=<%= showPage+1 %>'>下一頁
</a> <% } %> <% if(showPage<pageCount){ %><a class='f-12-black'
href='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&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='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&page=<%=i %>' <% if
(i==showPage){ %>selected <% } %>><%=i %></option><% } %></select>頁
</a></td>
</tr>
</tbody>
</form>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
<%
RsArticle.close();
}
Rs6.close();
}
stmt1.close();
%>