Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to implement Pagination

 
ranjan kumar panda
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can search the same or JDBC forum with the word "pagination". You'll get many threads discussing same.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Dhivya Arivalagan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try Pager Taglib.Its very easy and simple too.

The respective url is http://jsptags.com/tags/navigation/pager/pager-taglib-2.0.html#item
 
Naresh Rajan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
selected_page="";
lb = 0;
ub =recordsPerPage;
}
else
{// page is selected
isPageSelected = true;
pg = Integer.valueOf(selected_page).intValue();
lb = recordsPerPage*(pg-1);
ub = lb + recordsPerPage;
}

query="select * from temp";

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

int noofpages=0;
if(totalrecords%recordsPerPage==0)
noofpages = totalrecords/recordsPerPage;
else
noofpages = totalrecords/recordsPerPage +1;

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

do{
// get the details what ever you want
cnt++;
}while(rs.next()& (cnt<=ub))
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic