开发者

display next records by pressing next

开发者 https://www.devze.com 2022-12-25 20:09 出处:网络
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 recor开发者_StackOverflow社区ds. I want to keep track which sublist has alr

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 recor开发者_StackOverflow社区ds. 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消