This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi There, i am thinking to add items to shopping cart class. in jsp page i will take quantity and product sku .If the user select add cart i will take sku and quantity as a parametes in my servlet .my doubt is if he comes again and add more items then i have to change the quantity . i am keeping it in hash tabel. Thanks in advance
Not sure what your worry is but, here is how online shopping carts are typically implemented in JSP. First create a class to encapsulate a ShoppingCart item which maps to the product table in the database. Then when the user buys the first item (action=add), first check if you have a vector of ShoppingCartItem(s) in the session and if not, create it, add it to the session and and call it's addItem() method which should take the itemID as a parameter, no need to pass it any other info.
When the user updates the quantity for item X, iterate through the Vector and find its id, then call the setQuantity() method, which should take two parameters (itemID, newQuantity). If the user tries to add an item that's already in the shopping cart, just increment it's quantity by one, or ignore that command.
If you need some demonstration code, let me know and i will write you some quickly. Hope that helps.
In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer