Here i’m going to write, how to do pagination in Java. The situation is first count how many rows in the database table, then query the database by page size (how many rows you want to display on a web page).
In Jsp
int pageno=0;
if(pno==null)
{
pageno=1;
}
else
{
pageno=Integer.parseInt(pno);
}
int next=pageno+1;
int previous=pageno-1;
//Java method
ArrayList al=object.getData(pageno);
// do all your showing data logic here
//print the previous and next links
if(previous!=0){
Previous link (url.jsp?pno=previous)
}
int max=obj.getTotalRows(); // total number of rows from database table
int check=(next-1)*10; // each page 10 rows
if(check<max){ // print next link if check is less than total rows
Next link (url.jsp?pno=next)
}
In Java
public ArrayList getData(int pagenumber)
{
ArrayList al=new ArrayList();
int offset = (pagenumber – 1) * 10;
//write all the logic and query data with the limit offset
Query + limit offset ,10;
return al;
}
//for getting total rows
public int getTotalRows() {
//write your logic to get total count of the rows
Query total rows from db table
return total_rows;
}
Share or Bookmark This Post With :
|
|
Posted On November 3rd, 2008
Hi dude, i need the complete code … I use JSP/Servlet to do pagination and MySQL as my backend… Please help me regarding this…. |
|
|
Posted On December 6th, 2008
Nothing happend |
|
|
Posted On June 16th, 2009
pno is undefined whats that is that a hidden feild how will the value of pno change?????such that the page number changes……can u please give the complete code |
|
|
Posted On June 17th, 2009
Hello zaryaar, Here pno is not a hidden field, but the page number attached to the URL I hope this may help you. |
Leave a Reply
- dotProject – the Open Source Project Managem...
- The jQuery Form Plugin
- DocVerse has officially been acquired by Google
- HDGraph – a free tool for Windows to draw mu...
- RandomClass jQuery Plugin
- Paparazzi – a small utility for Mac OS X to ...
- Blocking SPAM using Postfix header_checks and Spam...
- Facebook, Paypal team up for virtual goods payment
- Opera Mini – the next generation mobile brow...
- XML/SWF Charts – powerful tool to create att...
- Send emails using PHPMailer an...
- Firefox Addons Essential for S...
- Free SEO Tools From SEOMoz.org...
- URL Rewriting for PHP Web Appl...
- Multiple Instances of Tomcat w...
- Apache 2.x + Tomcat 4.x + Load...
- Pagination in JSP/Java
- PHP – Mysql Open Source ...
- java.lang.OutOfMemoryError: Ja...
- HOW TO Subversion+Apache on Fe...





