Recently required projects. Due to time issues, I used the simplest method to make a query page + CheckBox selection and submission. I think it is very suitable for small projects and similar functions of the mail list. I will post my code below, hoping my friends will give me more questions.
The main code is written in JSP. Below is an apply_note.jsp:
<% @ Page contentType = "text/html; charset = GBK" language = "java" %>
<% @ Page import = "java. SQL. *" %>
<% @ Page import = "com. deepdo. common. connect. ConSql" %>
<% @ Taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic" %>
<% @ Taglib uri = "/WEB-INF/struts-bean.tld" prefix = "bean" %>
<Style type = text/css>
Td, th, p, span, div, a, A {font-size: 12px; text-decoration: none}
. Blak a {color: #000; text-decoration: none}
. Blak a: hover {color: # f00; text-decoration: underline}
</Style>
<Body>
<Jsp: include page = "/include/deepdo. jsp" flush = "true"/>
<Table width = "700" border = "0" align = "center" cellpadding = "0" cellspacing = "0" height = "450">
<Tr>
<Td valign = "top" class = "bg_td1" height = "450" width = "160">
<Jsp: include page = "/include/navigation. jsp" flush = "true"/>
</Td>
<Td valign = "top" class = "bg_td1" height = "450" width = "540">
<Table width = "590" border = "0" align = "center" cellpadding = "2" cellspacing = "2" bgcolor = "# FAF9F5">
<Tr>
<Td background = "resume/images/color.jpg" class = "font4">
Work application records </td>
</Tr>
</Table>
<Table width = "590" border = "0" align = "center" cellpadding = "4" cellspacing = "2">
<%
// Variable Declaration
Connection sqlCon; // database Connection object
Statement sqlStmt; // SQL Statement object
ResultSet sqlRst; // result set object
String strCon; // database connection String
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.
String strPage;
Int I;
// Set the number of records displayed on one page
IntPageSize = 10;
// 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;
}
// Obtain a TOMCAT-configured connection pool
SqlCon = ConSql. getCon ();
// Create a read-only SQL statement object that can be rolled
SqlStmt = sqlCon. createStatement (java. SQL. ResultSet. TYPE_SCROLL_INSENSITIVE, java. SQL. ResultSet. CONCUR_READ_ONLY );
// Prepare SQL statements
StrSQL = "select * from apply_note where userid =" + request. getAttribute ("userid ");
// Execute the SQL statement and obtain the result set
SqlRst = sqlStmt.exe cuteQuery (strSQL );
// Obtain the total number of records
SqlRst. last ();
IntRowCount = sqlRst. getRow ();
// Calculate the total number of pages
IntPageCount = (intRowCount + intPageSize-1)/intPageSize;
// Adjust the page number to be displayed
If (intPage> intPageCount) intPage = intPageCount;
%>
<Tr>
<Td align = "center" bgcolor = "# efefef" width = "150" height = "27"> positions applied for </td>
<Td align = "center" bgcolor = "# efefef" width = "140" height = "27"> company name </td>
<Td align = "center" bgcolor = "# efefef" width = "75" height = "27"> application time </td>
<Td align = "center" bgcolor = "# efefef" width = "25" height = "27"> <input type = CheckBox name = "selectAll" onClick = "selectAll (); "> </td>
</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;
While (I <intPageSize &&! SqlRst. isAfterLast ()){
%>
<Form name = "noteForm" action = "noteRemove. do" method = "post">
<Tr>
<Td> <a href = <% = sqlRst. getString ("url") %> target = "_ blank"> <% = sqlRst. getString ("job") %> </a> </td>
<Td> <% = sqlRst. getString ("unit") %> </td>
<Td> <% = sqlRst. getString ("date_time") %> </td>
<Td width = "26" align = "center"> <input type = CheckBox name = "id" value = <% = sqlRst. getString ("id") % >></td>
</Tr>
<%
SqlRst. next ();
I ++;
}
}
%>
<Tr>
<Td>
<A href = "note. dopage = 1"> homepage </a>
<% If (intPage> 1) {%> <a href = "note. dopage = <% = intPage-1 %>"> previous page </a> <%}
Else {%> <a href = "#" title = "already the first page"> previous page </a> <%} %>
<% If (intPage <intPageCount) {%> <a href = "note. dopage = <% = intPage + 1%>"> next page </a> <%}
Else {%> <a href = "#" title = "is the last page"> next page </a> <%} %>
<A href = note. dopage = <% = intPageCount %> last page </a>
</Td>
<Td>
Total <% = intPageCount %> page application records
Page <% = intPage %>