jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Pagination In JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Pagination In JSP Page" Watch "Pagination In JSP Page" New topic
Author

Pagination In JSP Page

Alicia Logan
Greenhorn

Joined: Aug 24, 2005
Posts: 14
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'.

Please do reply....
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
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.


keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
 
jQuery in Action, 2nd edition
 
subject: Pagination In JSP Page