A common JSP pagebean

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;
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.