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

Commit

Permalink
Fix error check product quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
htnghia1423 committed Mar 6, 2024
1 parent 5483afb commit 14f025b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,34 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}

String productIdParam = request.getParameter("productId");
String productQuantityParam = request.getParameter("productQuantity");

if (productIdParam == null || productIdParam.isEmpty()) {
request.setAttribute("message", "productNotExist");
request.setAttribute("message", "notInputProduct");
this.doGet(request, response);
return;
}

Integer productId = Integer.parseInt(productIdParam);
Integer productQuantity = Integer.parseInt(request.getParameter("productQuantity"));

if (productId == null) {
request.setAttribute("message", "notInputProduct");

if (productQuantityParam == null || productQuantityParam.isEmpty()) {
request.setAttribute("message", "notInputProductQuantity");
this.doGet(request, response);
return;
}

if (productQuantity == null) {
request.setAttribute("message", "notInputProduct");
if (!isInteger(productIdParam)) {
request.setAttribute("message", "productNotExist");
this.doGet(request, response);
return;
}

if (!isInteger(productQuantityParam)) {
request.setAttribute("message", "productQuantityNotExist");
this.doGet(request, response);
return;
}

Integer productId = Integer.parseInt(productIdParam);
Integer productQuantity = Integer.parseInt(productQuantityParam);

Optional<Product> product = Singleton.productDAO.getByID(productId);

Expand Down Expand Up @@ -96,4 +105,13 @@ private boolean checkCusIdParam(String customerIdParam) {
}
return true;
}

private boolean isInteger(String param){
try {
Integer.parseInt(param);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@
Chưa nhập tên sản phẩm. Vui lòng kiểm tra lại.
</div>
</c:when>
<c:when test="${requestScope.message eq 'productNotExist'}">
<c:when test="${requestScope.message eq 'notInputProductQuantity'}">
<div class="alert alert-danger text-center" role="alert">
Chưa nhập số lượng sản phẩm. Vui lòng kiểm tra lại.
</div>
</c:when>
<c:when test="${requestScope.message eq 'productQuantityNotExist'}">
<div class="alert alert-danger text-center" role="alert">
Chưa nhập số lượng sản phẩm cần mua. Vui lòng kiểm tra lại.
Nhập sai định dạng số lượng sản phẩm. Vui lòng kiểm tra lại.
</div>
</c:when>
<c:when test="${requestScope.message eq 'missingCustomer'}">
Expand Down Expand Up @@ -119,6 +124,7 @@
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/validate/validator.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>

<!--Danh sach goi y-->
<script>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/view/jsp/management/order/order.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<script src="<%=request.getContextPath()%>/view/assets/js/bootstrap.min.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>
</body>

</html>
1 change: 1 addition & 0 deletions src/main/webapp/view/jsp/others/login/forgot-password.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/validate/validator.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>

<!--Validate Forgot Password-->
<script>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/view/jsp/others/login/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/validate/validator.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>

<!--Validate Login-->
<script>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/view/jsp/others/login/new-password.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/validate/validator.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>

<!--Validate Forgot Password-->
<script>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/view/jsp/others/login/otp.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/validate/validator.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/alert-timeout.js"></script>

<!--Validate Forgot Password-->
<script>
Expand Down

0 comments on commit 14f025b

Please sign in to comment.