From 14f025b8d0cf0c1a73dfe5dec97f61b84acb947f Mon Sep 17 00:00:00 2001 From: Thunder Date: Wed, 6 Mar 2024 10:44:08 +0700 Subject: [PATCH] Fix error check product quantity --- .../management/order/AddProductIntoOrder.java | 36 ++++++++++++++----- .../order/add-product-into-order.jsp | 10 ++++-- .../view/jsp/management/order/order.jsp | 1 + .../view/jsp/others/login/forgot-password.jsp | 1 + .../webapp/view/jsp/others/login/login.jsp | 1 + .../view/jsp/others/login/new-password.jsp | 1 + src/main/webapp/view/jsp/others/login/otp.jsp | 1 + 7 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/hardingadonis/saledock/controller/management/order/AddProductIntoOrder.java b/src/main/java/io/hardingadonis/saledock/controller/management/order/AddProductIntoOrder.java index 48066b2..1559fdd 100644 --- a/src/main/java/io/hardingadonis/saledock/controller/management/order/AddProductIntoOrder.java +++ b/src/main/java/io/hardingadonis/saledock/controller/management/order/AddProductIntoOrder.java @@ -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 = Singleton.productDAO.getByID(productId); @@ -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; + } + } } diff --git a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp index 717bae0..d68df65 100644 --- a/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp +++ b/src/main/webapp/view/jsp/management/order/add-product-into-order.jsp @@ -46,9 +46,14 @@ Chưa nhập tên sản phẩm. Vui lòng kiểm tra lại. - + + + + @@ -119,6 +124,7 @@ + + diff --git a/src/main/webapp/view/jsp/others/login/forgot-password.jsp b/src/main/webapp/view/jsp/others/login/forgot-password.jsp index c4d7736..4740434 100644 --- a/src/main/webapp/view/jsp/others/login/forgot-password.jsp +++ b/src/main/webapp/view/jsp/others/login/forgot-password.jsp @@ -59,6 +59,7 @@ + + + +