A common JSP pagebean
Last Update:2018-12-08
Source: Internet
Author: User
Package com. shaccp. Web. util;
Import java. util. List;
Public class pagebean {
/**
*
*
* @ Author PPy
* Total totalrecords records
* List stores paging data.
* Pageno current page
* Pagesize page size
* Query stores the user query string
* Pageaction: servlet or action (struts) on the Operation page)
* Method (the method corresponding to the action in struts)
*
*
*/
Private int totalrecords;
Private 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 ){
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;
}
/**
* Return method for getting the total number of pages
* Totalrecords % pagesize = 0? (Totalrecords/pagesize) :( totalrecords/pagesize + 1)
*
* @ Return
*/
Public int gettotalpages (){
Return (totalrecords + pagesize-1)/pagesize;
}
/**
* Get the homepage
*
* @ Return
*/
Public int gettoppage (){
Return 1;
}
/**
* Get the 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 the last page
*
* @ Return
*/
Public int getbottompageno (){
Return gettotalrecords () = 0? 1: gettotalpages ();
}
// Method 1 of page navigation
Public String getpagetoolbar1 (){
String STR = "";
STR + = "<a href = '" + pageaction + "? Method = "+ method +" & userquery ="
+ Query + "& pageno =" + getpreviouspageno () + "& pagesize ="
+ Pagesize + "'> previous page </a> ";
STR + = "<a href = '" + pageaction + "? Method = "+ method +" & userquery ="
+ Query + "& pageno =" + getnextpageno () + "& pagesize ="
+ Pagesize + "'> next page </a> ";
Return STR;
}
// Link method 2 of page navigation
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;
}
}