JSP实现分页结果(2)

分页标题#e#

package org.ThreeLayer.Entity; import java.util.List; public class Page_S {//为了不呈现于重名,改了一下 private int currentPage; private int pageSize;//页面巨细,即页面数据个数 private int totalCount;//总数据 private int totalPage;//总页数 private List<Student> students; public Page_S() { } public Page_S(int currentPage, int pageSize, int totalCount, int totalPage, List<Student> students) { this.currentPage = currentPage; this.pageSize = pageSize; this.totalCount = totalCount; this.totalPage = totalPage; this.students = students; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; this.totalPage=this.totalCount%this.pageSize==0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1; } public int getTotalCount() { return totalCount; } public void setTotalCount(int totalCount) { this.totalCount = totalCount; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public List<Student> getStudents() { return students; } public void setStudents(List<Student> students) { this.students = students; } }

最后贴上index.jsp:

<%@page import="java.util.List"%> <%@page import="org.ThreeLayer.Entity.Student"%> <%@page import="org.ThreeLayer.Entity.Page_S"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>学生信息打点</title> </head> <body> <table border=1px> <tr> <th>学号</th> <th>姓名</th> <th>性别</th> <th>操纵</th> </tr> <% Page_S pagg=(Page_S)request.getAttribute("pag"); for(Student student:pagg.getStudents()) { %> <tr> <th><a href="FindStudentById_Servlet?uid=<%=student.getId()%>" ><%=student.getId() %></a></th> <th><%=student.getName() %></th> <th><%=student.getSex() %></th> <th><a href="DeleteStudent_Servlet?uid=<%=student.getId()%>" >删除</a></th> </tr> <% } %> </table> <a href="https://www.jb51.net/add.jsp" >增加</a> <% if(pagg.getCurrentPage()==0)//用户位于首页的时候 { %> <a href="findStudentByPage?currentPage=<%=pagg.getCurrentPage()+1%>" >下一页</a> <a href="findStudentByPage?currentPage=<%=pagg.getTotalPage()-1%>" >尾页</a> <% }else if(pagg.getCurrentPage()==pagg.getTotalPage()-1)//用户位于尾页的时候 { %> <a href="findStudentByPage?currentPage=0" >首页</a> <a href="findStudentByPage?currentPage=<%=pagg.getCurrentPage()-1%>" >上一页</a> <% }else//用户位于中间页面的时候 { %> <a href="findStudentByPage?currentPage=0" >首页</a> <a href="findStudentByPage?currentPage=<%=pagg.getCurrentPage()+1%>" >下一页</a> <a href="findStudentByPage?currentPage=<%=pagg.getCurrentPage()-1%>" >上一页</a> <a href="findStudentByPage?currentPage=<%=pagg.getTotalPage()-1%>" >尾页</a> <% } %> <br> </body> </html>

看一下结果图:

首先看数据库内容:

JSP实现分页功效

然后是首页:

JSP实现分页功效

下一页:

JSP实现分页功效

最后是尾页:

JSP实现分页功效

总的说明一下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdddx.html