提交 8c6f4fa9 编写于 作者: C CheungChingYin

添加分页功能

上级 0d2f1cdd
......@@ -65,10 +65,18 @@
float: right;
margin-right: 50px;
}
.pageNav{
margin-left: 200px;
}
</style>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String pages = request.getParameter("pages");
int startLine = (Integer.parseInt(pages)-1)*10;
%>
<div class="contain pull-left">
<form action="DaoSearch.jsp" class="form-inline ">
<h2>学生名单管理</h2>
......@@ -94,14 +102,21 @@
</tr>
</thead>
<tbody>
<%
request.setCharacterEncoding("UTF-8");
String sqlQuery = "SELECT * FROM stumanagementbyweb.studentinfo";
<%
int pageSize = 10;
String sqlQuery = "SELECT * FROM stumanagementbyweb.studentinfo limit "+startLine+","+pageSize;
String sqlAll = "SELECT * FROM stumanagementbyweb.studentinfo";
int pagesCount = 0;
int lastRow = 0;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stumanagementbyweb","root","123456");
Statement sql = con.createStatement();
Statement stat = con.createStatement();
ResultSet rs = sql.executeQuery(sqlQuery);
ResultSet rsAll = stat.executeQuery(sqlAll);
rsAll.last();
lastRow = rsAll.getRow();//记录最后一行
while(rs.next()){
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
......@@ -122,6 +137,37 @@
</tbody>
</table>
<div class="pageNav">
<ul class="pagination">
<%
int prePage;
if(pages.equals("1")){
prePage = 1;
}else{
prePage = Integer.parseInt(pages)-1;
}
%>
<li class="page-item"><a class="page-link" href="Contain.jsp?pages=<%=prePage%>">Previous</a></li>
<%
pagesCount = (lastRow % pageSize == 0) ? (lastRow / pageSize) : (lastRow / pageSize +1);
for(int i = 1;i<=pagesCount;i++){
out.print("<li class='page-item'>");
out.print("<a class='page-link' href='Contain.jsp?pages="+i+"'>"+i+"</a>");
out.print("</li>");
}
%>
<%
int nextPage;
if(pages.equals(pagesCount+"")){
nextPage = pagesCount;
}else{
nextPage = Integer.parseInt(pages)+1;
}
%>
<li class="page-item"><a class="page-link" href="Contain.jsp?pages=<%=nextPage%>">Next</a></li>
</ul>
</div>
</div>
</div>
......
......@@ -52,7 +52,7 @@
ps.setString(6,major);
ps.setString(7,college);
ps.executeUpdate();
out.print("<script type='text/javascript'>alert('添加学生信息成功!');window.location.href='Contain.jsp';</script>");
out.print("<script type='text/javascript'>alert('添加学生信息成功!');window.location.href='Contain.jsp?pages=1';</script>");
ps.close();
}
rs.close();
......
......@@ -60,7 +60,7 @@
ps.setString(7,college);
ps.setString(8,sourceId);
ps.executeUpdate();
out.print("<script type='text/javascript'>alert('更改学生信息成功!');window.location.href='Contain.jsp';</script>");
out.print("<script type='text/javascript'>alert('更改学生信息成功!');window.location.href='Contain.jsp?pages=1';</script>");
ps.close();
}
rs.close();
......
......@@ -27,7 +27,7 @@
ps = con.prepareStatement(sql);
ps.setString(1, id);
ps.executeUpdate();
out.print("<script type='text/javascript'>alert('删除学生信息成功!');window.location.href='Contain.jsp';</script>");
out.print("<script type='text/javascript'>alert('删除学生信息成功!');window.location.href='Contain.jsp?pages=1';</script>");
ps.close();
con.close();
}catch(Exception e){
......
......@@ -18,7 +18,7 @@
</head>
<body>
<ul class="nav nav-pills nav-stacked">
<li><a href="Contain.jsp" target="contain">学生管理</a></li>
<li><a href="Contain.jsp?pages=1" target="contain">学生管理</a></li>
<li><a href="AdminPasswordReset.jsp" target="contain">账号密码重置</a></li>
<li><a href="SystemExit.jsp" target="_parent">退出系统</a></li>
</ul>
......
......@@ -15,7 +15,7 @@ if((String)session.getAttribute("user")==null){
<frame src="Top.jsp" noresize="noresize" scrolling="yes" />
<frameset cols="30%,*">
<frame src="Left_nav.html" noresize="noresize" />
<frame src="Contain.jsp" name="contain" />
<frame src="Contain.jsp?pages=1" name="contain" />
</frameset>
</frameset>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册