Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
fix err 404 and set constrain for list product
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaqc committed Mar 1, 2024
1 parent dfa48ed commit 241e943
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
int limit = 10;

if (request.getParameter("page") != null) {
page = Integer.parseInt(request.getParameter("page"));
try {
page = Integer.parseInt(request.getParameter("page"));

} catch (Exception e) {
response.sendRedirect("./error-404");
return;
}
}

List<Product> list = Singleton.productDAO.pagination((page - 1) * limit, limit);
Integer count = Singleton.productDAO.count();
int totalPage = Singleton.productDAO.totalPages(limit);

list.isEmpty();

request.setAttribute("productList", list);
request.setAttribute("currentPage", page);
request.setAttribute("totalPage", totalPage);
Expand Down
109 changes: 59 additions & 50 deletions src/main/webapp/view/jsp/management/product/product.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,71 @@
<p class="text-primary m-0 fw-bold">Quản lý sản phẩm</p>
<a href="<%=request.getContextPath()%>/add-product" class="btn btn-primary btn-sm">Thêm sản phẩm</a>
</div>
<div class="card-body">
<div class="table-responsive table mt-2" id="dataTable" role="grid" aria-describedby="dataTable_info">
<table class="table my-0" id="dataTable">
<thead>
<tr>
<th>Mã sản phẩm</th>
<th>Tên sản phẩm</th>
<th>Phân loại</th>
<th>Thao tác</th>
</tr>
</thead>
<c:forEach items="${requestScope.productList}" var="product">
<tbody>
<c:if test="${!requestScope.productList.isEmpty()}">
<div class="card-body">
<div class="table-responsive table mt-2" id="dataTable" role="grid" aria-describedby="dataTable_info">
<table class="table my-0" id="dataTable">
<thead>
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.category.name}</td>
<td class="text-start">
<a class="btn btn-primary btn-sm" role="button" data-bs-toggle="tooltip" data-bss-tooltip="" style="margin: 2px;" title="Thông tin chi tiết" href="<%=request.getContextPath()%>/product-detail?id=${product.ID}">
<i class="la la-info-circle"></i>
</a>
<a class="btn btn-warning btn-sm" data-bs-toggle="tooltip" data-bss-tooltip="" style="margin: 2px;" title="Chỉnh sửa" href="<%=request.getContextPath()%>/update-product?id=${product.ID}" >
<i class="la la-edit"></i>
</a>
</td>
<th>Mã sản phẩm</th>
<th>Tên sản phẩm</th>
<th>Phân loại</th>
<th>Thao tác</th>
</tr>
</tbody>
</c:forEach>
</table>
</div>
<div class="row">
<div class="col-md-6 align-self-center">
<p id="dataTable_info" class="dataTables_info" role="status" aria-live="polite">
Hiển thị ${requestScope.currentPage * requestScope.limit < requestScope.numOfPro ? requestScope.currentPage * requestScope.limit : requestScope.numOfPro}
trên ${requestScope.numOfPro} sản phẩm
</p>
</thead>
<c:forEach items="${requestScope.productList}" var="product">
<tbody>
<tr>
<td>${product.code}</td>
<td>${product.name}</td>
<td>${product.category.name}</td>
<td class="text-start">
<a class="btn btn-primary btn-sm" role="button" data-bs-toggle="tooltip" data-bss-tooltip="" style="margin: 2px;" title="Thông tin chi tiết" href="<%=request.getContextPath()%>/product-detail?id=${product.ID}">
<i class="la la-info-circle"></i>
</a>
<a class="btn btn-warning btn-sm" data-bs-toggle="tooltip" data-bss-tooltip="" style="margin: 2px;" title="Chỉnh sửa" href="<%=request.getContextPath()%>/update-product?id=${product.ID}" >
<i class="la la-edit"></i>
</a>
</td>
</tr>
</tbody>
</c:forEach>
</table>
</div>
<div class="col-md-6">
<nav class="d-lg-flex justify-content-lg-end dataTables_paginate paging_simple_numbers">
<ul class="pagination">
<li class="page-item ${requestScope.currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" aria-label="Previous" href="<%=request.getContextPath()%>/product?page=${requestScope.currentPage - 1}"><span aria-hidden="true">«</span></a>
</li>
<c:forEach var="i" begin="1" end="${requestScope.totalPage}">
<li class="page-item ${i == requestScope.currentPage ? 'active' : ''}">
<a class="page-link" href="<%=request.getContextPath()%>/product?page=${i}">${i}</a>
<div class="row">
<div class="col-md-6 align-self-center">
<p id="dataTable_info" class="dataTables_info" role="status" aria-live="polite">
Hiển thị ${requestScope.currentPage * requestScope.limit < requestScope.numOfPro ? requestScope.currentPage * requestScope.limit : requestScope.numOfPro}
trên ${requestScope.numOfPro} sản phẩm
</p>
</div>
<div class="col-md-6">
<nav class="d-lg-flex justify-content-lg-end dataTables_paginate paging_simple_numbers">
<ul class="pagination">
<li class="page-item ${requestScope.currentPage == 1 ? 'disabled' : ''}">
<a class="page-link" aria-label="Previous" href="<%=request.getContextPath()%>/product?page=${requestScope.currentPage - 1}"><span aria-hidden="true">«</span></a>
</li>
<c:forEach var="i" begin="1" end="${requestScope.totalPage}">
<li class="page-item ${i == requestScope.currentPage ? 'active' : ''}">
<a class="page-link" href="<%=request.getContextPath()%>/product?page=${i}">${i}</a>
</li>
</c:forEach>
<li class="page-item ${requestScope.currentPage == requestScope.totalPage ? 'disabled' : ''}">
<a class="page-link" aria-label="Next" href="<%=request.getContextPath()%>/product?page=${requestScope.currentPage + 1}"><span aria-hidden="true">»</span></a>
</li>
</c:forEach>
<li class="page-item ${requestScope.currentPage == requestScope.totalPage ? 'disabled' : ''}">
<a class="page-link" aria-label="Next" href="ProductServlet?page=${requestScope.currentPage + 1}"><span aria-hidden="true">»</span></a>
</li>
</ul>
</nav>
</ul>
</nav>
</div>
</div>
</div>
</div>
</c:if>
<c:if test="${requestScope.productList.isEmpty()}">
<div class="card-body">
<div class="row">
<h3 style="text-align: center;">Không có sản phẩm nào để quản lí.</h3>
</div>
</div>
</c:if>
</div>
</div>
</div>
Expand Down

0 comments on commit 241e943

Please sign in to comment.