jsp 数组分页显示 (Inber 原创)

(搜索关键字 jsp,java,数组分页)

<%
/*
Inberkong
[email protected]
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("下一页");
 %>
 &nbsp;<a href='?pages=<%=intPageCount%>'> 尾页</a></td>
  </tr>
</table>

你可能感兴趣的:(jsp,qq,Yahoo)