Hi!
I would first suggest that you go to one of the online stores and take a look at the behaviour of their shopping carts. I tried
www.amazon.com and
www.buycds.com and I liked what I saw.
Here is what i believe you need:
1. A JavaBean which will act as your ShoppingCart Object
2. A database to hold your products
3. A
Servlet to act as a controller (e.g. a view could call the servlet when adding/removing items from your cart
4. A
JSP which can act as a 'View'. This jsp will allow you see the current state of the cart.
5. 1 or more jsps which will allow you to interact with the servlet (see point 3).
Here is how it all works:
This is called MVC.
You have a jsp that gets the items from your db and displays them on a table. You provide a link on this table which also embeds information such as productId etc so that you can forward this information to other pages. Call this jsp something like 'AddToShoppingCart.jsp'
When you click the 'Add' button on the 'AddToShoppingCart.jsp' it will then forward all the data to the 'ShoppingCartControllerServlet.java' file
The 'ShoppingCartControllerServlet.java' file merely takes the commands like 'add, remove or updateQuantity' from any of the jsps and processes them by calling the ShoppingCart class/Object. After it has done it's job it should automatically forward you back to the view (viewShoppingCart.jsp) so you can see the state of your cart.
The viewShoppingCart.jsp could use a nicely formatted table to display your cart and have buttons such as 'remove' or updateQuantity.
Well, that was just a brief explanation to give you an idea. There are a lot more issues involved here like making sure that you keep a ShoppingCart object in a session while the user is still shopping so that things don't get mixed up. You then have to allow the user to check-out like in a normal shop and not to mention the credit card handling mechanism.
I have done this for myself just out of curiosity and i would be happy to show you some of my code.
Good luck!!
[This message has been edited by ernest fakudze (edited October 15, 2001).]