servlet 实现mysql分页_servlet+mysql分页(上一页,下一页)

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){

%>

编辑 删除

}

%>

首页|

上一页|

下一页|

">尾页

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值