From fc6762a45911d1722db28958162cd187f8fcfac8 Mon Sep 17 00:00:00 2001 From: fujiangfer <1632816175@qq.com> Date: Tue, 30 Mar 2021 20:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E4=BF=AE=E6=94=B9=E5=87=BA?= =?UTF-8?q?=E7=8E=B0bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复跳转一直跳到第一页的问题 --- .../edu/fzu/postsearch/servlet/PostServlet.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/221801121&221801131/java/edu/fzu/postsearch/servlet/PostServlet.java b/221801121&221801131/java/edu/fzu/postsearch/servlet/PostServlet.java index 642f85d59..c3b46df10 100644 --- a/221801121&221801131/java/edu/fzu/postsearch/servlet/PostServlet.java +++ b/221801121&221801131/java/edu/fzu/postsearch/servlet/PostServlet.java @@ -31,18 +31,19 @@ public void service(HttpServletRequest req, HttpServletResponse resp) throws Ser int maxPage = 0;// 最大页 int pageCount = posts.size();// 得到查询出来的所有数据的数目 // 如果是第一次执行,就会接收不到数据 - if ((strNum == null)||(strNum.equals(""))) { - strNum = "0"; - } else {// 接收到了用户点击的第几(pageNum)页 - pageNum = Integer.parseInt(strNum); - if (pageNum < 0 || pageNum > maxPage)pageNum = 0; - } // 计算出要分多少页 if (pageCount % 31 == 0) { maxPage = pageCount / 31; } else { maxPage = pageCount / 31 + 1; } + if ((strNum == null)||(strNum.equals(""))) { + strNum = "0"; + } else {// 接收到了用户点击的第几(pageNum)页 + pageNum = Integer.parseInt(strNum); + if (pageNum < 0 || pageNum > maxPage)pageNum = 0; + } + req.setAttribute("maxPage", maxPage);// 存储最大页数 req.setAttribute("pageNum", pageNum);// 将当前页面存储起来,给分页页面使用 req.setAttribute("posts", posts);