Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pagination In JSP Page

 
Alicia Logan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic