It's not a secret anymore!
The moose likes JSP and the fly likes How to implement Pagination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to implement Pagination" Watch "How to implement Pagination" New topic

How to implement Pagination

ranjan kumar panda

Joined: Nov 27, 2005
Posts: 2
I am new to the pagination concept. I want to implement pagination in my website just like the one implemented in Yahoo mail serviece. I want ot display 20 records at a time and navigates through the pages with the help of NEXT and PREVIOUS links. Now let me tell you I have searches all the relevant forum and did not get any wanted code. Can any body give the code for it.'
NB : I don't wnat to use JSP Taglib or JSLT or java scrip or any additional thing. With the help of simple jdbc and any logical code i want to do the same in the JSP or Servlet. Please help me out.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
You can search the same or JDBC forum with the word "pagination". You'll get many threads discussing same.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

There is also an entry in the JSP FAQ for this question.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dhivya Arivalagan

Joined: Nov 29, 2005
Posts: 2
You can try Pager Taglib.Its very easy and simple too.

The respective url is
Naresh Rajan
Ranch Hand

Joined: Sep 08, 2005
Posts: 45
am doing the same thing in which i am calling the database to send me the next 20 records by sending some parameters (like timestamp, serial no and a flag that says what button has been pressed) in the last record for the "Next" button and some parameters in the first record for the "Previous" button.

These parameters form a part of the Stored procedure call from my servelet.

Am not a pro and thats why am here!!!
pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
This solution is through Java

you can make use of the
Methods provided by the ResultSet

I am Sending you the code for pagination

ResultSet rs=null;
boolean isPageSelected = false;
int lb = 0 , ub = 0 ,pg = 0,totalrecords=0,recordsPerPage=10;
// variables used in paging

String selected_page= request.getParameter("page");
if(selected_page == null || selected_page == "" || selected_page.equals("") )
{// page not selected
isPageSelected = false;
lb = 0;
ub =recordsPerPage;
{// page is selected
isPageSelected = true;
pg = Integer.valueOf(selected_page).intValue();
lb = recordsPerPage*(pg-1);
ub = lb + recordsPerPage;

query="select * from temp";

rs.last(); // Jump to last row
totalrecords = rs.getRow(); // get the row count
// reset to allow forward cursor processing

int noofpages=0;
noofpages = totalrecords/recordsPerPage;
noofpages = totalrecords/recordsPerPage +1;

int cnt = lb;
rs.absolute(lb+1); // move to record

// get the details what ever you want
}while( (cnt<=ub))

Pankaj Patil
I agree. Here's the link:
subject: How to implement Pagination
It's not a secret anymore!