<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<%
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage");
if(pages==null)
{
  pages="1";
}
try
{
  dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
  dipage=1; 
}
%>
<head>
<style type="text/css">
<!--
.STYLE1 {
    font-family: "华文行楷";
    font-size: 36px;
}
-->
</style>
</head>
<body>
//数据的连接
 <%
    Connection con;
    Statement sql;
    ResultSet rs;
    request.setCharacterEncoding("gb2312");
    try{
        Class.forName("com.mysql.jdbc.Driver");
    }catch(ClassNotFoundException e){
        out.print(e);
    }con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/zp","root","zhang");
    sql=con.createStatement();
    rs=sql.executeQuery("select * from fenye");
    while (rs.next()){%>
<form id="form1" name="form1" method="post" action="">
<%
         int countRecord=0;//记录条数
         int countPageRecord=0;//每页记录条数
         int countPage=0;//总页数
         countPageRecord=5;//每页5条记录,要设置每页记录条数就更改这个变量的值
         //得到记录的条数
         rs.last();
         countRecord=rs.getRow();
         //得到总页数
         if(countRecord/countPageRecord==0)
            countPage=countRecord/countPageRecord;
         else
            countPage=countRecord/countPageRecord+1;
         //把记录指针移至当前页第一条记录之前
         if((dipage-1)*countPageRecord==0)
            rs.beforeFirst();
         else
            rs.absolute((dipage-1)*countPageRecord);
            int i=0;
%>
  <table width="518" height="215" border="1" align="center">
    <tr>
      <td colspan="4" align="center"><span class="STYLE1">下面是查询的结果</span></td>
    </tr>
    <tr>
      <td width="123">ID</td>
      <td width="126">姓名</td>
      <td width="113">性别</td>
      <td width="128">年龄</td>
    </tr>
    
<% long id=rs.getLong(1);%>
    <tr>
      <td><%=id%></td>
      <td><%=rs.getString(2)%></td>
      <td><%=rs.getString(3)%></td>
      <td><%=rs.getLong(4)%></td>
    </tr>
<%
         i++;
        if(i>=countPageRecord){ 
        break; //当前页显示完,则退出循环
        }else
            out.print("共"+countRecord+"条记录,共"+countPage+"页,当前第"+dipage+"页,每页"+countPageRecord+"条记录,");
         if(dipage==1){
             break;
         }//当前是首页
              
         else//当前不是首页
         {
              out.print("<a href=fenye.jsp?dipage=1>首页</a>,");
              out.print("<a href=fenye.jsp?dipage="+(dipage-1)+">上一页</a>,");
           }
           if(dipage==countPage){
                   break;
           }//当前是末页
              
           else//当前不是末页
           {
              out.print("<a href=fenye.jsp?dipage="+(dipage+1)+">下一页</a>,");
              out.print("<a href=fenye.jsp?dipage="+countPage+">末页</a>");
           }          
           
      
%>
    <%}%>
    <%
    con.close();
    %>
  </table>
  
</form>
</body>
</html>



 
											






 
	    

 
	



