views:

55

answers:

1

I have a website in front page. I'm displaying 5 records. I want that when user clicks Next, he should be able to view next records. I want to keep track which sublist has already been shown to user. I am using an ArrayList. How to get next records each time user clicks on next button, using servlets?

+1  A: 

Pass two request parameters on press of the button: firstrow and rowcount. The firstrow represents the index of the first row to be displayed. The rowcount represents the amount of rows to be displayed at once.

In the servlet, just do the math. On press of Next button do firstrow += rowcount and on press of Prev button do firstrow -= rowcount (simplified example, you of course need to take overflows into account). Then query exactly that subset of data from database using DB-specific SQL, for example LIMIT firstrow OFFSET rowcount in MySQL and PostgreSQL. I've posted a more detailed answer before.

BalusC