pages.jsp
资源名称:0102010.rar [点击查看]
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:2k
源码类别:
教育系统应用
开发平台:
WORD
- <%@ page contentType="text/html;charset=gb2312" %>
- <%@ page import="java.sql.*"%>
- <html>
- <head>
- <title>web编程之分页显示</title>
- <body>
- <center><font color=red>用户资料表</font></center>
- <%
- int EveryPage=8;//每页显示的记录笔数;
- int OnPage=1; //显示的页数;
- int Total=0;//记录的笔数;
- int TotalPage=0;//记录的总页数;
- //下面是连接数据库;由于是简单的例子就不用JavaBean了;
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection conn=DriverManager.getConnection("jdbc:odbc:test");
- Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
- String sql="select * from test";
- ResultSet rs=stmt.executeQuery(sql);
- rs.last();//移到最后一条记录;
- Total=rs.getRow();//记录的笔数;
- if(Total%EveryPage==0)
- TotalPage=Total/EveryPage;
- else
- TotalPage=Total/EveryPage+1;
- String Pages=request.getParameter("Pages");
- if(Pages!=null)
- {
- OnPage=Integer.parseInt(Pages);
- if(OnPage>TotalPage)
- {
- OnPage=TotalPage;
- }
- else if(OnPage<=0)
- {
- OnPage=1;
- }
- }
- rs.absolute((OnPage-1)*EveryPage+1);
- %>
- <center>
- 用户<%=Total%>个,共<%=TotalPage%>页当前在第<font color=red><%=OnPage%></font>页
- </center>
- <br>
- <center>
- <table border=1 bordercolor=red>
- <tr>
- <td>用户编号</td>
- <td>用户名</td>
- <td>密码</td>
- </tr>
- <%
- for(int i=1;i<=EveryPage;i++)
- {
- %>
- <tr>
- <td><%=rs.getString("id")%></td>
- <td><%=rs.getString("name")%></td>
- <td><%=rs.getString("password")%></td>
- </tr>
- <%
- if(!rs.next())
- break;
- }
- rs.close();
- stmt.close();
- conn.close();
- %>
- </table>
- </center>
- <%
- if(OnPage!=1)
- {
- %>
- <br>
- <center>
- <a href=pages.jsp?Pages=<%=1%>>第一页</a>
- <a href=pages.jsp?Pages=<%=OnPage-1%>>上一页</a>
- </center>
- <%
- }
- if(OnPage!=TotalPage)
- {
- %>
- <center>
- <a href=pages.jsp?Pages=<%=OnPage+1%>>下一页</a>
- <a href=pages.jsp?Pages=<%=TotalPage%>>最后一页</a>
- </center>
- <%
- }
- %>
- <center>
- <form action=pages.jsp method=post>
- 转到<input type="text" size=2 name=Pages value=<%=OnPage%>>页
- </form>
- </center>
- </body>
- </html>