aspose file tools*
The moose likes JSP and the fly likes e-shop cart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "e-shop cart" Watch "e-shop cart" New topic
Author

e-shop cart

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

Hello,

i have a simple question on e-shop cart.I have a table in sql called products, were i store my products.Is it right to use a vector to keep track of the products the customer buys and then using a servlet to insert,delete and show products?

and ofcourse use a cookie to store the data.

Thnx in advance....
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Cookies only store strings, not vectors, so parts of your question do not make sense. Also, vector is an outdated class, ArrayList is preferred (details not important for this post though)

Session variable storage and management is far from "simple". Generally, you often use a cookie to keep a list of unique product ids and quantities for the items the customer has added to their cart as a string such as:

myItems = "4923=1&14591=4?19491=2"

which represents 1 of item 4923, 4 of item 14591, and 2 of item 19491 although the format is completely up to you. The String.split() is particularly useful for decoding these values.
[ November 01, 2005: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Scott Selikoff:
Also, vector is an outdated class, ArrayList is preferred (details not important for this post though)


No. Its not outdated. Actually, sometimes Vector is more suitable and preferred.

But agreed, ArrayList would be better in this scenerio, as it would be accessed by just a single thread.

For more differences about Vector and ArrayList please refer to the docs. There is no other better substitute.

Thanks.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
This is just to share.

You will find one more difference between ArrayList and Vector, which I couldn't get from the docs and never heard before.

This thread is discussing the difference
http://www.coderanch.com/t/327608/java/java/Difference-between-Arraylist-Vector

I am not sure about this difference.
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

Thnx guys

I appreciate the posts
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: e-shop cart