jQuery in Action, 2nd edition*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to implement Pagination" Watch "How to implement Pagination" New topic
Author

How to implement Pagination

ranjan kumar panda
Greenhorn

Joined: Nov 27, 2005
Posts: 2
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

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.

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is also an entry in the JSP FAQ for this question.
http://faq.javaranch.com/view?PaginationOrPaging


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

Joined: Nov 29, 2005
Posts: 2
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

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;
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))


Regards,
Pankaj Patil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement Pagination