Servlet to achieve paging effect
This example shares the specific code of servlet to realize paging effect for your reference. The specific contents are as follows
Paging algorithm:
Four variables need to be defined. They have their own uses. Int PageSize: how many records are displayed on each page. Int pagenow: what page do you want to display. Int pagecount: how many pages are there in total. Int rowcount: how many records are there in total
explain:
PageSize refers to the specified, and pagenow refers to the user's selection. Rowcount is obtained by querying from the table. Pagecount is calculated. The calculation formula is:
If using the statement: select field name list from table name where id between? and ? This SQL statement is really fast, but there is a problem, that is, if the table ID is deleted, there may be one less record on a page.
Therefore, the final method is the following statement: select top PageSize field name list from table name where id not in (select top PageSize * (pagenow-1) id from table name)
The implementation code is:
Execution results:
When the number of records displayed per page is 3:
Click the corresponding connection to successfully jump.
The last page is displayed as:
Corresponding code:
Click backward to stop jumping.
In order to show how the program controls the number of pages and the number of hyperlinks, change the number of records displayed per page to 1.
First page display effect:
Corresponding code:
Display effect when the current page number gradually increases:
Corresponding code:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.