JSP data page

xiaoxiao2021-03-06  53

Jsp data paging Author: He Shuangjiang

Keywords: Java JSP Data Page Yarshray He Shuangjiang

About data pages in web applications seem to be a very common topic, although many people have written similar articles, but I still want to express my views with text, although there is nothing new, but more or less will give you A little help. First. For data paging, my understanding is how many pages of a total of how many records are given for a given current page number and each page, and must know how many records have a total of how many records, and current The problem is displayed. Then I have a generally known according to the above analysis: the following questions: Conditions: Current page number per page record number total record number 1 Total number of pages: Total number = total record number / per page record number; IF The total record number of MODs // For the remainder, that is, the number of becoming points = total page number 1; END `2 Seeking the current record range The current record = current page number / total page * Total record number Current tail record = current first record number per page number -1;

Then we can complete the data pagination code based on the above analysis.

The code example is, for example,: <% @ page import = "java.sql. *"%> <% @ Page Import = "java.util. *"%>

<%! Int nowpagenum = 0; // Current page number int onePageCount = 10; // Per record number (currently assumed to be 10) int allRecordCount = 91; // Total record number (currently assumed to be 91 s) int AllPageCount = 0; // Total Total INT nowFirst = 0; // Current 1 Record INT nowLAST = 0; // Current Tail Record%> <% - Page INIT -%> <% // Get the total number of pages AllPageCount = AllRecordcount / OnePageCount; IF (AllRecordcount% OnePageCount> 0) {AllPageCount ;}

// Get the current record range IF (Request.getParameter ("nowPAGenum")! = Null) {nowfirst = (int) (allrecordcount * integer.parseint ("nowPAGenum") / allpagecount)) } Nowlast = nowfirst onePageCount-1;%>

<% - Data Initialization -%> <% Class.Forname ("Data Driver Name"); String Url = "JDBC: URL Name"; Connection Conn = DriverManager.getConnection (URL); java.sql.Statement CMD = conn.createStatement (); string SQL = "SQL Query Statement"; ResultSet RS = cmd.executeQuery (SQL); ArrayList Al = New ArrayList (); // Move to the most current page record for (int i = 0; I <% - Display Table -%>

Id < / TR> <% itrator it = al.iterator (); while (it.hasnext ()) {%>
<% = it.next ()%> <%} / * end while * /%> <% for (int i = 0; i 转载请注明原文地址:https://www.9cbs.com/read-81814.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.117, SQL: 9