try{condition="select * from employee_info"; sql=conn.createStatement(); rs=sql.executeQuery(condition); int intPageSize; //一页显示的记录数 int intRowCount; //记录总数 int intPageCount; //总页数 int intPage; //待显示页码 %> </div> intPageSize = 2; //设置一页显示的记录数 String strPage = request.getParameter("page"); //取得待显示页码 if(strPage==null){ //表明在QueryString中没有page这一个参数,此时显示第一页数据 intPage = 1; } else{//将字符串转换成整型 intPage = java.lang.Integer.parseInt(strPage); if(intPage<1) intPage = 1; } out.print("<table border='1' width='100%'>"); out.print("<tr>"); out.print("<th >"+"雇员号"); out.print("<th >"+"姓名"); out.print("<th >"+"出生日期"); out.print("<th >"+"薪水"); out.print("<th >编辑</th >"); out.print("<th >删除</th >"); out.print("</tr>"); rs.last(); //光标指向查询结果集中最后一条记录 intRowCount = rs.getRow(); //获取记录总数 if(intRowCount%intPageSize==0){ intPageCount=intRowCount/intPageSize; }else{ intPageCount=intRowCount/intPageSize+1; } if(intPage>intPageCount) intPage = intPageCount; //调整待显示的页码 if(intPageCount>0){ rs.absolute((intPage-1) * intPageSize + 1); //将记录指针定位到待显示页的第一条记录上 int i = 0; while(i<intPageSize && !rs.isAfterLast()){ //显示数据 out.print("<tr>"); String id=rs.getString(1); out.print("<td >"+id+"</td>"); out.print("<td >"+rs.getString(2)+"</td>"); out.print("<td >"+rs.getDate("birthday")+"</td>"); out.print("<td >"+rs.getInt("salary")+"</td>"); out.print("<td><a href=modify.jsp?id="+id+">编辑</a></td>"); out.print("<td ><a href=delete.jsp?id="+id+" onclick=return(confirm('确定删除吗?'))>删除</a></td>"); out.print("</tr>") ; rs.next(); i++; } } out.print("</table>");%> <div align="center"> 第<%=intPage%>页 共<%=intPageCount%>页 <% if(intPage<intPageCount){ %> <a href="admin1.jsp?page=<%=intPage+1%>">下一页</a> <% } if(intPage>1){%> <a href="admin1.jsp?page=<%=intPage-1%>">上一页</a> <% } rs.close(); sql.close(); conn.close(); } catch(SQLException e) { out.print(e); } %> </div>
125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/4053.html