Simple paging display effect code implemented by JSP

  • 2021-09-05 00:39:22
  • OfStack

This paper describes the simple paging display effect code realized by JSP. Share it for your reference, 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; //1 Number of records displayed on the page 
int intRowCount; // Total number of records 
int intPageCount; // Total pages 
int intPage; // Page number to be displayed 
java.lang.String strPage;
int i;
// Settings 1 Number of records displayed on the page 
intPageSize = 4;
// Get the page number to be displayed 
strPage = request.getParameter("page");
if(strPage==null){// Indicates that in the QueryString Not in page This 1 Parameters, at this time, the first 1 Page data 
intPage = 1;
}
else{// Convert a string to an integer 
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
// Loading JDBC Driver 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Set the database connection string 
strCon = "jdbc:odbc:heyang";
// Connect to a database 
sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","");
// Create 1 Read-only that can be scrolled SQL Statement object 
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";
// Execute SQL Statement and get the result set 
sqlRst = sqlStmt.executeQuery(strSQL);
// Get the total number of records 
sqlRst.last();//?? Cursor at the end 1 Row 
intRowCount = sqlRst.getRow();// Get the current line number 
// Count the total number of pages 
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
// Adjust the page number to be displayed 
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> Membership management </title>
</head>
<body>
<form method="POST" action="fenye1.jsp">
 No. 1 <%=intPage%> Page   Altogether <%=intPageCount%> Page 
<%if(intPage<intPageCount){%><a
href="fenye1.jsp?page=<%=intPage+1%>"> Under 1 Page 
</a><%}%> <%if(intPage>1){%><a href="fenye1.jsp?page=<%=intPage-1%>">
 Upper 1 Page </a><%}%>
 Go to the :<input type="text" name="page" size="8">  Page 
<span><input class=buttonface type='submit' value='GO' name='cndok'></span>
</form>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<th> User name </th>
<th width='8%'> Delete </th>
</tr>
<%
if(intPageCount>0){
// Position the record pointer to the first of the page to be displayed 1 On a record 
sqlRst.absolute((intPage-1) * intPageSize + 1);
// Display data 
i = 0;
String user_id,user_name;
while(i<intPageSize && !sqlRst.isAfterLast()){
user_id=sqlRst.getString(1);
user_name=sqlRst.getString(2);
%>
<tr>
<td><%=user_id%></td>
<td><%=user_name%></td>
<td width='8%' align='center'><a href="delete.jsp?user_id=<%=user_id%>"
onClick="return newwin(this.href);"> Delete </a></td>
</tr>
<%
sqlRst.next();
i++;
}
}
%>
</table>
</body>
</html>
<%
// Close the result set 
sqlRst.close();
// Shut down SQL Statement object 
sqlStmt.close();
// Close the database 
sqlCon.close();
%>

I hope this article is helpful to everyone's JSP programming.


Related articles: