JSP display by PAGE
<% @ 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; // number of records displayed on one page
Int intRowCount; // The total number of records.
Int intPageCount; // the total number of pages.
Int intPage; // the page number to be displayed.
Java. lang. String strPage;
Int I;
// Set the number of records displayed on one page
IntPageSize = 4;
// Obtain the page number to be displayed
StrPage = request. getParameter ("page ");
If (strPage = null) {// indicates that the page parameter is not found in QueryString. the first page of data is displayed.
IntPage = 1;
}
Else {// convert a string to an integer
IntPage = java. lang. Integer. parseInt (strPage );
If (intPage <1) intPage = 1;
}
// Load the JDBC driver
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
// Set the database connection string
StrCon = "jdbc: odbc: heyang ";
// Connect to the database
SqlCon = java. SQL. DriverManager. getConnection (strCon, "sa ","");
// Create a read-only SQL statement object that can be rolled
SqlStmt =
SqlCon. createStatement (java. SQL. ResultSet. TYPE_SCROLL_INSENSITIVE, java. SQL. Result
Set. CONCUR_READ_ONLY); // prepare the SQL statement
StrSQL = "select user_id, user_name from userinfo order by user_id desc ";
// Execute the SQL statement and obtain the result set
SqlRst = sqlStmt.exe cuteQuery (strSQL );
// Obtain the total number of records
SqlRst. last ();//?? Cursor in the last line
IntRowCount = sqlRst. getRow (); // obtain the current row number
// Calculate 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> member management </title>
</Head>
<Body>
<Form method = "Post" Action = "fenye1.jsp">
Page <% = intpage %> total page <% = intpagecount %>
<% IF (intpage <intpagecount) {%> <
Href = "fenye1.jsp? Page = <% = intpage + 1%> "> next page
</A> <% }%> <% IF (intpage> 1) {%> <a href = "fenye1.jsp? Page = <% = intPage-1 %> ">
Previous Page </a> <% }%>
Go to page: <input type = "text" name = "page" size = "8">
<Span> <input class = buttonface type = 'submit 'value = 'Go' name = 'cndok'> </span>
</Form>
<Table border = "1" cellspacing = "0" cellpadding = "0">
<Tr>
<TH> id </Th>
<TH> User Name </Th>
<TH width = '8% '> Delete </Th>
</Tr>
<%
If (intPageCount> 0 ){
// Locate the record pointer to the first record on the page to be displayed.
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 ();
// Close the SQL statement object
Sqlstmt. Close ();
// Close the database
Sqlcon. Close ();
%>