首页 > 其他 > 详细

分页实现

时间:2014-11-29 10:30:38      阅读:311      评论:0      收藏:0      [点我收藏+]
pages.jsp
<%@ page contentType="text/html;charset=gbk" %>
<%
//分页变量定义
final int e=3;//每页显示的记录数
int totalPages=0;//页面总数
int currentPage=1;//当前页面
int totalCount=0;//数据库中数据的总记录数
int p=0;//当前页面所显示的第一条记录的索引
//读取当前待显示的页面的编号
String tempStr=ruquest.getParameter("currentPage");
if(tempStr!==null&&tempStr.equals("")){
currentPage=Integer.parseInt(tempStr);

}


//分页预备
rs=stat.executeQuery("select count(*) from Books");
//计算总记录数
while(rs.next()){
totalCount=rs.getInt(1);
}
//计算机总的页数
totalPage=((totalCount%e==0)?(totalCount/e):(totalCount/e+1));
if(totalPages==0) totalPages=1;
//修正当前页面的编号,确保1<=currentPage<totalPages
if(currentPage>totalPages){
currentPage=tatolPages;
}
else if(currentPage<1){
currentPage=1;
}
//就算当前页面所显示的第一条记录的索引
p=(currentPage-1)*e;
String sql="select ID,Name,Title,Price from Books order by ID limit "+p"+","+e;
rs=stmt.executeQuery(sql);
%>
<%--显示页标签--%>
页码:
<%for(i=1;i<totalPages;i++){
if(i==currentPage){
%>
<%=i%>
<%}else{%>
<a href="dbaccess2.jsp?currentPage<%=i%>"><%=i%></a>
<%}%>
<%}%>
&nbsp;共<%totalPages%>页,共<%=totalCount%>条记录

分页实现

原文:http://blog.csdn.net/hephec/article/details/41592893

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!