index.jsp
查看所有学生
FindAll.java
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.StudentDao;
import com.daoImpl.StudentDaoImpl;
import com.entity.Student;
public class FindAll extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StudentDao sd=new StudentDaoImpl();
String str=request.getParameter("n");
//总行数
int lineCount=sd.countStudent();
//每页的行数
int pageSize=7;
//总共的页数
int pageCount=(int)Math.ceil(lineCount*1.0/pageSize);
int n = 1;
if(str == null || str.equals("")){
n = 1;
}else if(str.equals("a")){
n = (Integer)request.getSession().getAttribute("pageNow");
n--;
}else if(str.equals("b")){
n = (Integer)request.getSession().getAttribute("pageNow");
n++;
}else if(str.equals("1")){
n=1;
}else{
n=pageCount;
}
if(n>pageCount){
n=pageCount;
}
if(n<1){
n=1;
}
request.getSession().setAttribute("pageNow", n);
request.getSession().setAttribute("pageCount", pageCount);
ArrayList list=sd.getAllStudent(n,pageSize);
request.getSession().setAttribute("list", list);
response.sendRedirect("showAllStudent.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
showAllStudent.jsp
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
显示所有学生学号 | 姓名 | 性别 | 年龄 | 班级 | DID | 生日 | 成绩 | 英文名 | 电话 | 操作 |
---|
ArrayList list=(ArrayList)session.getAttribute("list");
for(Student s:list){
%>
编辑 删除}
%>
首页|
上一页|
下一页|
">尾页
更多推荐
servlet 实现mysql分页_servlet+mysql分页(上一页,下一页)
发布评论