The example in this article describes the simple pagination display effect code for the JSP implementation. Share to everyone for your reference, specific as follows:
<%@ page contenttype= "text/html;charset=gb2312"%> <%@ page language= "java" import= "java.sql.*"%> < Script language= "JavaScript" > function newwin (URL) {var newwin=window.open (URL, "Newwin", "Toolbar=no,location=no,
Directories=no,status=no, menubar=no,scrollbars=yes,resizable=yes,width=600,height=450 ");
Newwin.focus ();
return false; } </SCRIPT> <script language= "JavaScript" > Function submit10 () {self.location.replace ("fenye1.jsp")} < /script> <%//Variable declaration java.sql.Connection Sqlcon; Database Connection object Java.sql.Statement sqlstmt; SQL statement Object Java.sql.ResultSet Sqlrst; Result set object java.lang.String Strcon; Database connection string java.lang.String strSQL; SQL statement int intpagesize; The number of records displayed on one page int introwcount; Total records int intpagecount; Total pages int intpage;
To display the page number java.lang.String strpage;
int i;
Set the number of records displayed on a page intpagesize = 4;
Get the number to be displayed strpage = request.getparameter ("page"); if (strpage==null) {//indicates that there is no page this parameter in QueryString, the first page of data is displayed intpage = 1;} else{//converts the string to integer intpage = Java.lang.IntegeR.parseint (strpage);
if (intpage<1) intpage = 1;
}//Load JDBC driver class.forname ("Sun.jdbc.odbc.JdbcOdbcDriver");
Sets the database connection string strcon = "Jdbc:odbc:heyang";
Connection Database Sqlcon = java.sql.DriverManager.getConnection (Strcon, "sa", "");
Create a read-only SQL statement object that can be scrolled sqlstmt = Sqlcon.createstatement (java.sql.resultset.type_scroll_insensitive,java.sql.result
SET.CONCUR_READ_ONLY)//Prepare SQL statement strSQL = "Select User_id,user_name from UserInfo order by user_id Desc";
Executes the SQL statement and gets the result set Sqlrst = Sqlstmt.executequery (strSQL); Get the total number of records sqlrst.last ();//??
The cursor Introwcount = Sqlrst.getrow () on the last line and/or the current line number//Count total page Intpagecount = (introwcount+intpagesize-1)/intpagesize;
Adjusts the page number if (intpage>intpagecount) intpage = Intpagecount to be displayed; %>