ShowUser.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户展示界面</title>
</head>
<body>
<body bgcolor="#2EFEF7">
<center>
<%@include file="title.jsp" %>
<br>
<h1><a href="index.jsp">返回重新登录</a>
<a href="success.jsp">返回管理界面 </a>
</h1>
<br>
<hr>
<br><br><br>
<%
int pageSize=3;
int pageNow=1;//默认显示第一页
int rowCount=0;//从数据库中获得
int pageCount;//计算得到
//接收pageNow
String tmpPageNow=request.getParameter("pageNow");
if(tmpPageNow!=null)
{
//接收到pageNow
pageNow=Integer.parseInt(tmpPageNow);
}
//链接数据库,验证密码
//1.加载驱动
// 驱动程序名
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
//2.得到链接
// URL指向要访问的数据库名world
String url = "jdbc:mysql://localhost:3306/db_01";
Connection conn=DriverManager.getConnection(url,"root","root");
//3.得到statement
Statement statement = conn.createStatement();
//4查询数据库
String sql="select count(*) from user";
ResultSet rs = statement.executeQuery(sql);
if(rs.next())
{
rowCount=rs.getInt(1);
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
sql="select * from user limit "+(pageNow-1)*pageSize+","+pageSize;
rs=statement.executeQuery(sql);
%>
<table border="1px">
<tr><td>用户名</td><td>密码</td><td>性别</td><td>出生日期</td><td>毕业学校</td><td>学 历</td><td>通 信 地 址</td><td>联 系 电 话</td><td>Email</td></tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
<td><%=rs.getString(8)%></td>
<td><%=rs.getString(9)%></td>
<td><%=rs.getString(10)%></td>
</tr>
<%
}
%>
</table>
<%
//上一页
if(pageNow>1)
{
out.println("<a href='showUser.jsp?pageNow="+(pageNow-1)+"'>["+"上一页"+"]</a>");
}
for(int i=0;i<pageCount;i++)
{
out.println("<a href='showUser.jsp?pageNow="+(i+1)+"'>["+(i+1)+"]</a>");
}
//下一页
if(pageNow<pageCount)
{
out.println("<a href='showUser.jsp?pageNow="+(pageNow+1)+"'>["+"下一页"+"]</a>");
}
%>
<br><br><br>
<%@include file="footer.jsp" %>
</center>
</body>
</html>
查看后续代码请看这里👉后续代码
网友评论