JSP implementation of a simple page-display effect code _JSP programming

Source: Internet
Author: User
Tags odbc

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; %> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.