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 9095ddf..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,32 +18,25 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); - List products = Singleton.productDAO.getAll(); - int page = 1; - int limit = 10; - 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); + List list = Singleton.productDAO.pagination((page - 1) * LIMIT, LIMIT); Integer count = Singleton.productDAO.count(); - int totalPage = Singleton.productDAO.totalPages(limit); - - list.isEmpty(); + 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("limit", LIMIT); request.setAttribute("page", "product");