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.
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
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.
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.