• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

e-shop cart

 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx guys

I appreciate the posts
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic