类似百度谷歌分页算法实现
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="com.modorn.Bean.UserDao"%> <%@page import="com.modorn.Bean.UserBean"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'manger.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <style type="text/css"> table{ border-collapse:collapse; } td{ border:#ccc solid 1px; padding:5px; } </style> </head> <body> <%!int pageNow = 1;%> <% String userName = (String) request.getSession().getAttribute("userName"); if (userName == null) { response.sendRedirect("login.jsp?erro=1"); } if (request.getParameter("pageNow") != null) { pageNow = Integer.parseInt(request.getParameter("pageNow")); } %> <center> 欢迎 <font color=red><%=userName%></font>登录 <br /> <br /> <br /> <% UserDao userDao = new UserDao(); int pageNum = userDao.getPageNum(); ArrayList<UserBean> list = userDao.fenyeInfo(pageNow); int countPage = userDao.getCounPage(); %> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th> 用户ID </th> <th> 用户名 </th> <th> 密码 </th> <th> 用户类型 </th> </tr> <% for (int i = 0; i < list.size(); i++) { out.println("<tr><td>" + list.get(i).getUserId() + "</td>"); out.println("<td>" + list.get(i).getUserName() + "</td>"); out.println("<td>" + list.get(i).getPassW() + "</td>"); out.println("<td>" + list.get(i).getGrade() + "</td></tr>"); } %> </table> <!--分页算法开始--> <% if (pageNow != 1) { out.println("<a href=manger.jsp?pageNow=" + (pageNow - 1) + ">【上一页】</a>"); } int start; if(pageNow < pageNum){ start = 1; }else{ start = pageNow - 10 + 1; } for (int i = start; i <= countPage && i <= pageNow + pageNum; i++) { if(i == pageNow){ out.println(i); continue; } out.println("<a href=manger.jsp?pageNow=" + i + ">[" + i + "]</a>"); } if (pageNow != countPage) { out.println("<a href=manger.jsp?pageNow=" + (pageNow + 1) + ">【下一页】</a>"); } %> <!--分页算法结束--> </center> </body> </html>
相关推荐
justaipanda 2020-09-07
人工智能快报 2020-11-21
xfcyhades 2020-11-20
Pokemogo 2020-11-16
guangcheng 2020-11-13
深圳克林斯曼 2020-11-09
机器之心 2020-11-06
Urchindong 2020-11-04
Michael 2020-11-03
章鱼之家 2020-10-29
fengyeezju 2020-10-14
hanfuquan0 2020-10-12
89347543 2020-10-10
韩伟佳 2020-10-09
lybbb 2020-09-29
关于学习本身 2020-09-24
Angelia 2020-09-11
刘炳昭 2020-09-10