[java] view plaincopy
-
- int pageSize = 15;
- int pageNow = 1;
- int rowCount = 0;
- int pageCount = 0;
-
-
- Class.forName("com.mysql.jdbc.Driver");
-
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testuser=root&password=root");
-
-
- String sPageNow = req.getParameter("pageNow");
- if(sPageNow != null){
-
- pageNow = Integer.parseInt(sPageNow);
- }
-
-
- ps = conn.prepareStatement("select count(*) from user");
- rs = ps.executeQuery();
- if(rs.next()){
- rowCount = rs.getInt(1);
- }
-
-
- if(rowCount%pageSize == 0){
- pageCount = rowCount/pageSize;
- }else {
- pageCount = rowCount/pageSize + 1;
- }
-
-
-
- ps = conn.prepareStatement("select * from user limit "+pageSize*(pageNow - 1+", "+pageSize+"");
- rs = ps.executeQuery();
-
-
- pw.println("<table border=1>");
-
- pw.println("<tr><th>id</th><th>name</th><th>passwd</th><th>email</th><th>grade</th></tr>");
-
- while(rs.next()){
- pw.println("<tr>");
- pw.println("<td>"+rs.getInt(1)+"</td>");
- pw.println("<td>"+rs.getString(2)+"</td>");
- pw.println("<td>"+rs.getString(3)+"</td>");
- pw.println("<td>"+rs.getString(4)+"</td>");
- pw.println("<td>"+rs.getInt(5)+"</td>");
- pw.println("</tr>");
- }
-
- pw.println("</table>");
-
- if(pageNow > 1){
-
- pw.println("<a href="wel?pageNow=" mce_href="wel?pageNow=""+(pageNow-1)+">上一页</a>");
- }
-
-
- for(int i = pageNow; i <= pageNow+9; i++){
- pw.println("<a href="wel?pageNow=" mce_href="wel?pageNow=""+i+">"+i+"</a>");
- }
- if(pageNow < pageCount){
-
- pw.println("<a href="wel?pageNow=" mce_href="wel?pageNow=""+(pageNow+1)+">下一页</a>");
- }