jsp - Problem with updating the hashmap -


Good day!

I am shopping cart and I decided to temporarily store it. Hamspap (session) before customer check-out is my problem that I am having difficulty updating

JSP:

  & lt; C: forEach var = "cart" item within the item  

items = "$ {cartList}" & gt; & Lt; Form method = "POST" action = "shoppingCartUpdate" & gt; $ {Cart.value.productId} $ {cart.value.productName} $ {cart.value.price} & lt; Input type = "text" value = "$ {cart.value.quantity}" name = "volume" & gt; & Lt; Input type = "submit" value = "update" name = "update" & gt; & Lt; / Form & gt; & Lt; / C: foreach & gt;

My servlet:

  int productId = integer.print (request.getParameter ("productId")); // Here error .. int quantity = Integer.parseInt (request.getParameter ("Quantity")); Cart item = (cart) cartList.get (productId); Item.setQuantity (quantity); Double price = item.getPrice (); Sub-sum = price * quantity; CartList.put (Product ID, Item);   

Even if I have entered the second number in the field of quantity, then it never updates. Heat I can correct it Thanks.

Edit: The error is as follows:

  WARNING: StandardDrifferValve [ShoppingCant]: PWC 1406: servlet.service () for servlet shopcart throw exception java.lang Gave. Number format expansion: blank    

You request as productId Parameters are expected, but you are not giving it in any form as it comes in the form of null and it is not capable of parse as an integer and therefore the NumberFormatException: null .

Add the following form to:

  & lt; Input type = "hidden" name = "product ID" value = "$ {cart.value.productId}" />   

is not related to a concrete problem,

  cartList.put (product ID, item);   

This row is redundant, remove it, remove it. This is Java, PHP or nothing is already in the Item map. You have not removed it from the map All changes will only appear in the map in the item context because it refers to the same object.

Comments