java========================
/**
* Pagination entity class
* @version [version number, Nov 9,]
*/
Public class Page {
private int currentpage;//current page
private int pageSize;//Paging size
private int totalnum;//total number of bars
private int totalpage;//Total pages
private String URL;//url address
//private Object obj;
Private String firstpageurl;//Home
private String Nextpageurl;//Next page
private String Prepageurl;//Previous Page
private String Lastpageurl;//Last
Public Page (int currentpage, int pageSize, int totalnum, String url) {
super ();
this.pagesize = pageSize;
this.totalnum = totalnum;
this.url = URL;
totalpage = totalnum/pagesize;
//If the total number of bars can not be divided by the number of pages per page, total pages plus 1
if (0!=totalnum%pagesize) {
totalpage + +;
}
if (currentpage>totalpage) {//The current page is greater than the total number of pages, the value of gross position pages is assigned to the current page
this.currentpage = totalpage;
}else if (currentpage<1) {//The current page is greater than 0 o'clock, the current page is assigned a value of 1
this.currentpage = 1;
}else {
this.currentpage = currentpage;
}
}
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;
}
public int Gettotalnum () {
return totalnum;
}
Public void Settotalnum (int totalnum) {
this.totalnum = totalnum;
}
public int Gettotalpage () {
return totalpage;
}
Public void Settotalpage (int totalpage) {
this.totalpage = totalpage;
}
Public String GetUrl () {
return URL;
}
Public void SetUrl (String url) {
this.url = URL;
}
/**
* Set Home address
* Create on Nov
*/
Public void Setfirstpageurl () {
StringBuffer firsturl = new StringBuffer (URL);
firsturl.append ("currentpage=1&pagesize="). Append (pageSize);
This.firstpageurl = firsturl.tostring ();
}
/**
* Get home address
* Create on Nov 9,
*/
Public String Getfirstpageurl () {
Setfirstpageurl ();
return this.firstpageurl;
}
/**
* Set last address
* Create on Nov
*/
Public void Setlastpageurl () {
StringBuffer lasturl = new StringBuffer (URL);
lasturl.append ("currentpage=")
. Append (totalpage)
. Append ("&pagesize=")
. Append (pageSize);
This.lastpageurl = lasturl.tostring ();
}
/**
* Get last address
* Create on Nov 9,
*/
Public String Getlastpageurl () {
Setlastpageurl ();
return this.lastpageurl;
}
/**
* Set next page address
* Create on Nov
*/
Public void Setnextpageurl () {
StringBuffer nexturl = new StringBuffer (URL);
nexturl.append ("currentpage=")
. Append (currentpage+1)
. Append ("&pagesize=")
. Append (pageSize);
This.nextpageurl = nexturl.tostring ();
}
/**
* Get the next page address
* Create on Nov 9,
*/
Public String Getnextpageurl () {
Setnextpageurl ();
return this.nextpageurl;
}
/**
* Set up a previous page address
* Create on Nov
*/
Public void Setprepageurl () {
StringBuffer preUrl = new StringBuffer (URL);
preurl.append ("currentpage=")
. Append (currentPage-1)
. Append ("&pagesize=")
. Append (pageSize);
This.prepageurl = preurl.tostring ();
}
/**
* Get a previous page address
* Create on Nov 9,
*/
Public String Getprepageurl () {
Setprepageurl ();
return this.prepageurl;
}
}
jsp=========================
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<div align= "center" >
<c:choose>
<c:when test= "${page.currentpage! = 1}" >
<!--The current page is not the homepage, the first and previous pages are connected--
<a href= "${page.firstpageurl}" > Home </a>
<a href= "${page.prepageurl}" > Prev </a>
</c:when>
<c:otherwise>
<!--The current page is home, the first and previous pages are not connected--
Home prev
</c:otherwise>
</c:choose>
<!--All pages are listed when the total number of pages is less than 5 o'clock
<c:if test= "${page.totalpage<=5}" >
<c:foreach begin= "1" end= "${page.totalpage}" var= "I" step= "1" >
<c:if test= "${page.currentpage==i}" >
${i}
</c:if>
<c:if test= "${page.currentpage!=i}" >
<a href= "${page.url}currentpage=${i}&pagesize=${page.pagesize}" >[${i}]</a>
</c:if>
</c:forEach>
</c:if>
<!--When the total number of pages is greater than 5 o'clock, only 5 pages are listed, distributed around the current page.
<c:if test= "${page.totalpage>5}" >
<!--begin is 2 pages smaller than the current page, end is 2 pages larger than the current page- -
<c:set var= "Begin" >${page.currentPage-2}</c:set>
<c:set var= "End" >${page.currentPage+2}</c:set>
<!--The current page is less than 3 o'clock, in order to display a page number of 5, push the last number of pages back to the corresponding number--
<c:if test= "${begin<1}" >
<c:foreach begin= "1" end= "${end-begin+1}" var= "I" step= "1" >
<c:if test= "${page.currentpage==i}" >
${i}
</c:if>
<c:if test= "${page.currentpage!=i}" >
<a href= "${page.url}currentpage=${i}&pagesize=${page.pagesize}" >[${i}]</a>
</c:if>
</c:forEach>
</c:if>
<!--The current page is greater than and the total number of pages is less than 3 o'clock, in order to display the number of pages 5, the page to display the most front-end pages push forward- and
<c:if test= "${end>page.totalpage}" >
<c:foreach begin= "${begin-(End-page.totalpage)}" end= "${page.totalpage}" var= "I" step= "1" >
<c:if test= "${page.currentpage==i}" >
${i}
</c:if>
<c:if test= "${page.currentpage!=i}" >
<a href= "${page.url}currentpage=${i}&pagesize=${page.pagesize}" >[${i}]</a>
</c:if>
</c:forEach>
</c:if>
<!--The current page is greater than 2, and the difference from the total number of pages is greater than 2 o'clock, the number of pages before the current page 2 page to the 2 page--
<c:if test= "${begin>=1 and End<=page.totalpage}" >
<c:foreach begin= "${begin}" end= "${end}" var= "I" step= "1" >
<c:if test= "${page.currentpage==i}" >
${i}
</c:if>
<c:if test= "${page.currentpage!=i}" >
<a href= "${page.url}currentpage=${i}&pagesize=${page.pagesize}" >[${i}]</a>
</c:if>
</c:forEach>
</c:if>
</c:if>
<!--wow haha --
<c:choose>
<c:when test= "${page.currentpage! = page.totalpage}" >
<!--The current page is not last, the next and last pages are connected--
<a href= "${page.nextpageurl}" > Next </a>
<a href= "${page.lastpageurl}" > Last </a>
</c:when>
<c:otherwise>
<!--The current page is last, the next and last pages are not connected--
next last
</c:otherwise>
</c:choose>
Total ${page.totalnum} bar ${page.totalpage} page
<!--The total number of pages is greater than 5 o'clock, the Jump box is displayed
<c:if test= "${page.totalpage>5}" >
<form action= "${page.url}pagesize=${page.pagesize}" method= "Post" style= "Display:inline" >
to <input type= "text" name= "CurrentPage" onkeyup= "This.value=this.value.replace (/[^\d]/g, ')" onafterpaste= " This.value=this.value.replace (/[^\d]/g, ') "size=" 4 "maxlength=" 9 "/> page <input type=" submit "value=" Jump ">
</form>
</c:if>
</div>
Java Paging Code