mysql 分页技术

 

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="com.jzm.javabean.User"%>
<%@page import="com.jzm.javabean.ConnDB" %>
<%@page import="com.jzm.javabean.DB_User" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <%!
  int intPageSize =2;   //每页显示的记录数
  int currPageBegin;    //起始记录索引
  int intPageCount;   //总页数
  int intPage;          //待显示页码
  String  strPage;      //用户请求页码
  %>
  </head>
  <body bgcolor="cfef">
      查询的所有用户如下!
 <%
     Vector<User> vector = null;
  DB_User   dbUser = new  DB_User(new ConnDB()); 
  vector = dbUser.getAllUsers(); 
  //取得待显示页码
  strPage = request.getParameter("page"); 
  System.out.print("strpage=="+strPage);
  if(strPage == null)
  {
    intPage = 1;
  }else
  { 
     intPage = Integer.parseInt(strPage);
     if(intPage<1)    
       intPage=1;    
  }
  
  //计算总页数
  intPageCount =(vector.size()+intPageSize-1)/intPageSize;
  //调整待显示的页码
  if(intPage > intPageCount)
  intPage = intPageCount;
 
  //计算每一页的起始记录索引
  currPageBegin = intPage*intPageSize - intPageSize;
%>
 

 <table  border=1 cellspacing=0 width=80%>
<tr>
<td>会员用户名</td>
<td> 密码</td>
<td>性别</td>
<td> 邮箱</td>
<td> 权限</td>
<td>删除该会员</td>
<td>修改该会员</td>
</tr>
<%
   for(int i=currPageBegin; i<intPage*intPageSize && i<vector.size();i++)
   {
      User user = (User)vector.elementAt(i);
%>
<tr bgcolor="#f0ffff">
   <td><%out.print(user.getName());%></td>
     <td><%out.print(user.getPassword());%>  </td>
       <td><%out.print(user.getSex());%>  </td>
         <td><%out.print(user.getEmail());%>  </td>
           <td><%out.print(user.getPower());%>  </td>
           <td><form action ="delete_user.jsp" method="post">
           <input type="hidden" name="name" value=<%=user.getName()%>>
            <input type="submit" name="delete" value="删除" onclick="return confirm('是否真的删除此用户')"></form></td>              
           <td><form action ="modify_user.jsp" method="post">
            <input type="hidden" name="name" value=<%=user.getName()%>>
            <input type="submit" name="mod" value="修改"></form></td>     
          </tr>                          
<%}%>
 </table>
 <table align="center">
 <tr><td align="right"> 第<%=intPage%>页  共<%=intPageCount%>页
 <%
    if(intPage>1){
  %>
   <a href="showAllUser.jsp?page=<%=intPage-1%>">上一页</a>
  <%
  }else{
   %>
    上一页
   <%}
    %>
    <%if(intPage < intPageCount){ %>
    <a href="showAllUser.jsp?page=<%=intPage+1%>">下一页</a>
    <%}else{ %>
           下一页
    <%} %>
   </td>
   </tr>
   </table> 
  
<center> 
 <h1><a href="addUser.jsp">增加用户</a></h1>
 </center>
 
  </body>
</html>

你可能感兴趣的:(mysql,vector,String,user,input,import)