A general JSP paging pagebean_jsp programming
Last Update:2017-01-18
Source: Internet
Author: User
Package com.shaccp.web.util;
Import java.util.List;
public class Pagebean {
/**
*
*
* @author ppy 2008-10-18 14:3:56
* Total Records of totalrecords
* List to save paging data
* PageNo Current Page
* PageSize Page size
* Query saves a string of user queries
* Pageaction Action-Paging servlet or action (struts)
* Method (the method of action in struts)
*
*
*/
private int totalrecords;
Private list List;
private int pageno;
private int pageSize;
Private String query;
Private String pageaction;
Private String method;
public void Setpageaction (String pageaction) {
This.pageaction = pageaction;
}
public void Setmethod (String method) {
This.method = method;
}
Public List getlist () {
return list;
}
public void setlist (list list) {
This.list = list;
}
public int Getpageno () {
return pageno;
}
public void Setpageno (int pageno) {
This.pageno = PageNo;
}
public int getpagesize () {
return pageSize;
}
public void setpagesize (int pageSize) {
This.pagesize = pageSize;
}
public int gettotalrecords () {
return totalrecords;
}
public void settotalrecords (int totalrecords) {
This.totalrecords = totalrecords;
}
public void Setquery (String query) {
this.query = query;
}
/**
* method to get total pages
* totalrecords%pagesize==0? (totalrecords/pagesize):(totalrecords/pagesize+1)
*
* @return
*/
public int gettotalpages () {
Return (totalrecords + pageSize-1)/pageSize;
}
/**
* Get Home
*
* @return
*/
public int gettoppage () {
return 1;
}
/**
* Get a previous page
*
* @return
*/
public int Getpreviouspageno () {
if (PageNo <= 1)
return 1;
Else
return (PAGENO-1);
}
/**
* Get the next page
*
* @return
*/
public int Getnextpageno () {
if (PageNo >= gettotalpages ()) {
return gettotalpages () = = 0? 1:gettotalpages ();
} else {
return PageNo + 1;
}
}
/**
* Get Last
*
* @return
*/
public int Getbottompageno () {
return gettotalrecords () = = 0? 1:gettotalpages ();
}
How to link page paging navigation one
Public String getPageToolBar1 () {
String str = "";
STR + + "<a href= '" + pageaction + "? method=" + Method + "&userquery="
+ query + "&pageno=" + getpreviouspageno () + "&pagesize="
+ pageSize + "' > Prev </a>";
STR + + "<a href= '" + pageaction + "? method=" + Method + "&userquery="
+ query + "&pageno=" + getnextpageno () + "&pagesize="
+ pageSize + "' > next page </a>";
return str;
}
How to link page paging navigation two
Public String getPageToolBar2 () {
String str = "";
int pagesplit = (PAGENO/5) * 5;
for (int i = PageSplit-1 I < (pagesplit + 6); i++) {
if (I <= 0) {
else if (PageNo = i) {
STR + + i + "";
else if (i > Gettotalpages ()) {
} else {
STR + + "<a href= '" + pageaction + "? Method=" + Method
+ "&userquery=" + query + "&pageno=" + i + "&pagesize="
+ pageSize + "' >" + i + "</a>" + "";
}
}
return str;
}
}