jsp页面数据分页模仿百度分页效果

2021-06-23 10:06

阅读:439

YPE html>

标签:==   border   utf-8   ati   结束   encoding   charset   pageinfo   integer   

import="web09.shop.DBUtil"%>
import="java.sql.ResultSet"%>
import="java.sql.PreparedStatement"%>
import="java.sql.Connection"%>数据分页
class="tt" border="1" align="center" width="80%" cellpadding="10"> DBUtil dbutil=new DBUtil(); Connection conn=dbutil.getCon(); //Connection conn = new DBUtil().getCon(); PreparedStatement pstmt1 = conn.prepareStatement("select count(*) from student"); ResultSet rs1 = pstmt1.executeQuery(); rs1.next(); int recordCount = rs1.getInt(1); //记录总数int pageSize = 10; //每页记录数int start=1; //显示开始页int end=10; //显示结束页int pageCount = recordCount%pageSize==0 ? recordCount/pageSize : recordCount/pageSize+1; int currPage = request.getParameter("p")==null ? 1 : Integer.parseInt(request.getParameter("p")); currPage = currPage : currPage; currPage = currPage>pageCount ? pageCount : currPage; PreparedStatement pst = conn.prepareStatement("select * from student limit ?,?"); pst.setInt(1,currPage*pageSize-pageSize); pst.setInt(2,pageSize); ResultSet rs = pst.executeQuery(); while(rs.next()){ %> } %>
ID 姓名 年龄 专业
class="page"> out.print(String.format("首页",1)); if(currPage>=7){ start=currPage-5; end=currPage+4; } if(start>(pageCount-10)){ start=pageCount-9; } if(currPage>1){ out.print(String.format("上一页",currPage-1)); } for(int i=start;i){ if(i>pageCount) break; String pageinfo=String.format("%d",i,i); if(i==currPage){ pageinfo=String.format("%d",i); } out.print(pageinfo); } if(currPagepageCount){ out.print(String.format("下一页",currPage+1)); } out.print(String.format("尾页",pageCount)); %>

请根据自己的项目、包名修改

 

jsp页面数据分页模仿百度分页效果

标签:==   border   utf-8   ati   结束   encoding   charset   pageinfo   integer   

原文地址:http://www.cnblogs.com/fqszywz/p/7162290.html


评论


亲,登录后才可以留言!