<%
/*
Inberkong
inber520@yahoo.com.cn
QQ:27096282
數組分頁技術
arrayTest.jsp
*/
String [] contentArray={};
contentArray=new String[125];
for(int i=0;i<125;i++)
{
contentArray[i]="ayyayValue"+String.valueOf(i);
}
int intRowCount; //記錄總數 125
int intPage=-1; //待顯示頁碼
int intPageCount; //總頁數
int intPageSize; //一頁顯示的記錄數 6
intPageSize = 6;
if(request.getParameter("pages")==null)
intPage=1;
else
intPage=Integer.parseInt(request.getParameter("pages"));
intRowCount=125;//記錄總數
//記算總頁數
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
int startRecord=(intPage-1)*intPageSize;
int endRecord=(intPage*intPageSize-1);
while(startRecord<=endRecord && startRecord<=(intRowCount-1))
{
out.print("contentArray["+startRecord+"]:"+contentArray[startRecord]+"<BR>");
startRecord=startRecord+1;
}
%>
<table width="77%" height="15" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="43%" bgcolor="#CCCCCC"></td>
<td width="57%" bgcolor="#CCCCCC"><a href="?pages=1" >首頁</a>
<%
if((intPage-1)<1)
out.print("上一頁");
else
out.print("<a href='?pages="+(intPage-1)+"'>上一頁</a>");
%>
<%
if(intPage<intPageCount)
out.print("<a href='?pages="+(intPage+1)+"'>下一頁</a>");
else
out.print("下一頁");
%>
<a href='?pages=<%=intPageCount%>'> 尾頁</a></td>
</tr>
</table>