[Html]
<% @ Page language = "java" pageEncoding = "gb2312" %>
<% @ Page contentType = "text/html; charset = gb2312" %>
<% Request. setCharacterEncoding ("gb2312"); %>
<% @ Page import = "java. util. *, java. lang. *, java. SQL. *, javax. naming. *, javax. SQL. *" %>
<% @ Page errorPage = "error.html" %>
<Html> www.2cto.com
<Head> <meta http-equiv = Content-Type content = "text/html; charset = gb2312"> <Body>
<% Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Int pageSize, rowCount, pageCount, curPage;
PageSize = 5;
PageCount = 1;
String strPage = request. getParameter ("page ");
If (strPage = null) curPage = 1;
Else {
CurPage = Integer. parseInt (strPage); // set the current page by Parameters
If (curPage <1) curPage = 1;
}
%>
<% Try {
InitialContext ctx = new InitialContext ();
DataSource ds = (DataSource) ctx. lookup ("java: comp/env/MySqlDS ");
Con = ds. getConnection ();
Stmt = con. createStatement ();
Rs1_stmt.exe cuteQuery ("select * from infos ");
Rs. last ();
RowCount = rs. getRow ();
PageCount = (rowCount + pageSize-1)/pageSize;
If (curPage> pageCount) curPage = pageCount;
} Catch (SQLException e ){
System. out. println (e. toString ());
}
%>
<Table width = "100%"> <tr> <td>
Page: <% = curPage %>/<% = pageCount %> page <% = pageSize %> items/page </td> </tr>
</Table>
<Table width = "80%"> <tr>
<Th> Number </th> <th> Name </th> <th> Activity </th> <th> Score </th> </tr>
<% If (pageCount> 0) rs. absolute (curPage-1) * pageSize + 1 );
Int I = 0;
While (I <pageSize &&! Rs. isAfterLast () {%>
<Tr align = "center"> <td> <% = rs. getString (1) %> </td> <% = rs. getString (2) %> </td>
<Td> <% = rs. getString (3) %> </td> <% = rs. getString (4) %> </td> </tr>
<%
Rs. next ();
I ++;
} %>
</Table>
<% If (curPage> 1) {%>
<A href = "MyJsp. jsp? Page = <% = curPage-1 %> "> previous page </a> <%} %>
<% If (curPage <pageCount) {%>
<A href = "MyJsp. jsp? Page = <% = curPage + 1%> "> next page </a> <%} %>
</Body> <% Rs. close ();
Stmt. close ();
Con. close ();
%>