servlet部分
@WebServlet("/fyTwoServlet")
public class fyTwoServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// 从页面中得到currentPage和rows,若没有则初始化
String currentPage = req.getParameter("currentPage");
String rows = req.getParameter("rows");
if (currentPage == null || currentPage.equals("")){
currentPage = "1";
}
if (rows == null || rows.equals("")){
rows = "3";
}
// 调用service
IFenyeService ifs = new FenyeServiceImpl();
FenyeBean<Teacher> fenyeBean = ifs.findTeaByPage(Integer.parseInt(currentPage),Integer.parseInt(rows));
// 返回fenyeBean类
req.setAttribute("fenyeBean",fenyeBean);
req.getRequestDispatcher("list.jsp").forward(req,resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}
jsp页面
判断{
当前页==1时,显示首页
当前页!=1时,显示上一页
当前页 >= totalPage(总页数)时,显示尾页
当前页 != totalPage(总页数)时,显示下一页
}
循环:循环显示页数,当点击第几页时,跳转到对应页数