JSP翻頁功能代碼
<%int intPageSize; //一頁顯示的記錄數
int intRowCount; //記錄總數
int intPageCount; //總頁數
int intPage; //待顯示頁碼
String strPage;
//設置一頁顯示的記錄數
intPageSize = 25;
//取得待顯示頁碼
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中沒有page這一個參數,此時顯示第一頁數據
intPage = 1;
}else{//將字符串轉換成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage< 1){
intPage = 1;
}
}
Rs=connJB.executeQuery(sql);
Rs.absolute(1);
//獲取記錄總數
Rs.last();
intRowCount = Rs.getRow();
//記算總頁數
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//調整待顯示的頁碼
if(intPage >intPageCount) intPage = intPageCount;
if(intPageCount >0){
//將記錄指針定位到待顯示頁的第一條記錄上
Rs.absolute((intPage-1) * intPageSize+1);
//顯示數據
i = 0;
while(i< intPageSize && !Rs.isAfterLast()){
if(!className.equals("行業分類")){
//id=Rs.getInt("INFORMATION_ID");
strId=Rs.getString("INFORMATION_ID");
subjectName=Rs.getString("INFORMATION_NAME");
informationRank=Rs.getString("INFORMATION_RANK");
%>
<tr>
<td width="4%" height="25" valign="middle"><div align="center">◇</div></td>
<td width="96%"><a href="index2.jsp?INFORMATION_ID=<%=strId%>&INFORMATION_RANK=<%=informationRank%>" ><%=subjectName%></a></td>
</tr>
<% }else{
strId=Rs.getString("SUB_CLASS_VALUE");
subjectName=Rs.getString("SUB_CLASS_VALUE");
%>
<tr>
<td width="4%" height="25" valign="middle"><div align="center">◇</div></td>
<td width="96%"><a href="index_way.jsp?SMALL_CLASS=<%=strId%>" ><%=subjectName%></a></td>
</tr>
<%}%>
<%
Rs.next();
i++;
}Rs.close();
i=0;
%>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td valign="top" bgcolor="#F2F2F2">
<div align="left">
</div></td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#8C8C8C">
<tr>
<td height="22" align="center" bgcolor="#FFFFFF">第<%=intPage%>頁 共<%//=intRowCount%>條記錄/共<%=intPageCount%>頁
<%
if(intPage<2){
out.print("首頁 | 上一頁");
}else{%>
<a href="index.jsp?CLASS_NAME=<%=className%>&SUBJECT_NAME=<%=titleName%>">首頁 </a> | <a href="index.jsp?page=<%=intPage-1%>&CLASS_NAME=<%=className%>&SUBJECT_NAME=<%=titleName%>">上一頁</a>
<%}%>
|
<%
if((intPageCount-intPage)<1)
{
out.print("下一頁 | 尾頁");
}else{%>
<a href="index.jsp?page=<%=intPage+1%>&CLASS_NAME=<%=className%>&SUBJECT_NAME=<%=titleName%>">下一頁</a> | <a href="index.jsp?page=<%=intPageCount%>&CLASS_NAME=<%=className%>&SUBJECT_NAME=<%=titleName%>">尾頁</a>
<%}
}
else{
out.print("<center><table width=776 border=0 align=center cellpadding=0 cellspacing=1 bgcolor=#000000><tr><td bgcolor=#FFFFFF><center>目前還沒有內容!</center></td></tr></table></centre>");
}%>
其中sql為具體的SQL語句.
最後更新:2017-04-03 14:54:20