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%>" class="t8"><%=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%>" class="t8"><%=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语句.
上一篇:【window】系统禁止运行脚本


下一篇:无人化运维离我们有多远?阿里智能化运帷平台深度揭秘