my dog learned polymorphism
The moose likes JSP and the fly likes JSP Pagination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Pagination" Watch "JSP Pagination" New topic

JSP Pagination

gautam anand

Joined: Jun 02, 2004
Posts: 22

I have a JSP page in which i am displaying a number of values in simple HTML table using for loops. Since there are around 1000 entries i want to divide the exisiting page into multiple pages.I would appreciate if someone could provide an example of pagination or how it can be achieved.

Your help would be sincerely appreciated.

Gagan Gulati

Joined: Jul 27, 2004
Posts: 7
Are you picking up these values from the database and then trying to show them ?
Or are you hard coding the values in the pages ?
Using DB, one easy way of doing it wud be to to show the 10/20/50 values on each page and do a next which grabs the next 50 values. You can write a simple Javabean method which does so or in the same JSP, you can submit the request with these paramters, and do getParameter() in the beginning of the page and retrieve values.

Let me know if u want to do it with Db...
I have worked quite a lot on it

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

"gags gags",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
Alka Sharma

Joined: Sep 02, 2002
Posts: 16
For achieving this, either you can fire a query to db everytime user clicks on next or previous button or fetch all of them in memory (in array or some other datastructure which maintains sequence) at one go as that would be faster.
But again that depends upon the no if records you are expecting in db which are going to be fetched.
You'll have to keep flags to check whether user has clicked on previous or next and manipulate data accordingly.
Also, you'll have to maintain counters to find out the starting no. and no of records displyed.
e.g if you are displaying 26-50 records then your starting counter will be 26, no of records displayed will be 25 and say if user clicked on next, u would know that you have to show 51-75 (26+25) - (50+25) records.

Hope this helps.
I agree. Here's the link:
subject: JSP Pagination
It's not a secret anymore!