diff --git a/src/main/java/io/hardingadonis/saledock/controller/management/product/ProductServlet.java b/src/main/java/io/hardingadonis/saledock/controller/management/product/ProductServlet.java index 3cfff48..476a328 100644 --- a/src/main/java/io/hardingadonis/saledock/controller/management/product/ProductServlet.java +++ b/src/main/java/io/hardingadonis/saledock/controller/management/product/ProductServlet.java @@ -10,6 +10,7 @@ @WebServlet(name = "ProductServlet", urlPatterns = {"/product"}) public class ProductServlet extends HttpServlet { + final static int LIMIT = 10; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) @@ -17,10 +18,26 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); - List products = Singleton.productDAO.getAll(); - Integer productCount = Singleton.productDAO.count(); - request.setAttribute("productCount", productCount); - request.setAttribute("products", products); + int page = 1; + if (request.getParameter("page") != null) { + try { + page = Integer.parseInt(request.getParameter("page")); + } catch (Exception e) { + response.sendRedirect("./error-404"); + return; + } + } + + List list = Singleton.productDAO.pagination((page - 1) * LIMIT, LIMIT); + Integer count = Singleton.productDAO.count(); + int totalPage = Singleton.productDAO.totalPages(LIMIT); + + request.setAttribute("productList", list); + request.setAttribute("currentPage", page); + request.setAttribute("totalPage", totalPage); + request.setAttribute("numOfPro", count); + request.setAttribute("limit", LIMIT); + request.setAttribute("page", "product"); request.getRequestDispatcher("/view/jsp/management/product/product.jsp").forward(request, response); diff --git a/src/main/webapp/view/jsp/management/product/product.jsp b/src/main/webapp/view/jsp/management/product/product.jsp index 964c461..0051d5a 100644 --- a/src/main/webapp/view/jsp/management/product/product.jsp +++ b/src/main/webapp/view/jsp/management/product/product.jsp @@ -28,60 +28,78 @@

Quản lý sản phẩm

Thêm sản phẩm -
-
- - - - - - - - - - - + +
+
+
Mã sản phẩmTên sản phẩmPhân loạiThao tác
+ - - - - + + + + - - -
${product.code}${product.name}${product.category.name} - - - - - - - Mã sản phẩmTên sản phẩmPhân loạiThao tác
-
-
-
-

Hiển thị ${requestScope.productCount} trên ${requestScope.productCount} sản phẩm

+ + + + + ${product.code} + ${product.name} + ${product.category.name} + + + + + + + + + + + +
-
- +
+
+

+ Hiển thị ${requestScope.currentPage * requestScope.limit < requestScope.numOfPro ? requestScope.currentPage * requestScope.limit : requestScope.numOfPro} + trên ${requestScope.numOfPro} sản phẩm +

+
+
+ +
-
+ + +
+
+

Không có sản phẩm nào để quản lí.

+
+
+
- + <%@include file="../../../common/_footer.jsp" %> - + <%@include file="../../../common/_goback.jsp" %> @@ -89,5 +107,5 @@ - +