This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi All, I want to implement pagination using Servlets and JavaBeans. The problem that i am facing right now is that i am having a keyword search in my jsp which may query the DB and may return upto 3000 records at one time. I want to use pagination that the user is able to view 25 records on one page and then is able to move onto another page by clicking on the second link which shows '2'.
Write a class called Pagination that will contain the details of the records that are displayed in this page. Say,
1. First record index in the current page 2. Last record index in the current page 3. Total rows / page 4. Total number of rows 5. Current Page
These details can be updated and put on the session with every request for paging. Let's assume:
Current Page = 1 Rows/page = 10 Total number of rows = 50
When the user now clicks on the link "2", get the current set of row indices (from the Pagination object in Session), calculate the next index, display the next (second) set of rows, (11-20) in the page. Also, update the fields accordingly in the Pagination object in the session. Hyperlink "1". Remove hyperlink "2".
To improve performance, if you do not want to fetch all the rows, use "fetch first" clause in your query. When the user exhausts all the records and wants to view more, then fetch more.