• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JSP Pagination

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.

Thanks
Gautam
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

-G
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.

Thanks!
bear
Forum Bartender
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gautam,
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.
Thanks
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic