Meaningless Drivel is fun!
The moose likes JSP and the fly likes Pagination Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Pagination Problem" Watch "Pagination Problem" New topic

Pagination Problem

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 219

I had 4000+ records. I already worked on a kind of pagination where for every page number, request hits the database. I want to
modify the design .

First i want store 300 records in arraylist from database. i will show 25 records for each page number. so for each page click, request will not hit the database. It fetches records from arraylist. If arraylist get scarce of records then another 300 records should be fetched and then displayed.

Any one having ideas or suggestions, Please share....:)

Vipul Kumar

Vipul Kumar
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63874

Sounds like a simple matter of book-keeping to me. You just need to keep track of what you have on hand and what you have already shown.

Give the code a try and post with specific problems you are having with it.

[Asking smart questions] [About Bear] [Books by Bear]
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 219
Thanks Bear

This is my Action Class code.

This is PaginationUtil class which supports ....

My Dao class:

In Dao code there is duplicate code. I mean class loading and getting connection. After completing the whole thing then i will modify them. Please check the logic...

I am getting ArrayIndexOutOfBoundsException.

my JSP page

I used scriptlets in my jsp code. Please ignore it. Anyway i will change the code. I am more concentrating on the pagination . If pagination get succeed then i will change the scriptlet code.

For the first time list is iterating fine. after first 300 records pagination , i will fetch next 300 records from database. fetched records iam storing them in arraylist from index 0 to 299. I am calculating fromIndex and toIndex (i.e. sublist for pagination) based on pageNumber. based on page number fromIndex and toIndex values are some 290 to 318. But in the arraylist index is from 0 to 300.

This clearly states that my design is missing something. Please correct this and share your ideas to generalize it.

Vipul Kumar.
I agree. Here's the link:
subject: Pagination Problem
It's not a secret anymore!