user2961971
user2961971

Reputation: 287

Save Item to a Cart using a Session?

I was wondering how to go about saving an item to the cart using a session? My idea is the user will click a button "save" and then it will save on a larger cart where they can view all of their items. Now, this is where I get lost. I am new to sessions and cookies. So when the user clicks the save, I want the items in the cart to save to a session and then be posted to the big cart when they click on the page "big cart". How do I go about saving the items to a session to view in a larger cart format?

I am working in JSP and Java in this case.

Upvotes: 0

Views: 2423

Answers (1)

Hussain Marvi
Hussain Marvi

Reputation: 455

The session object is a logical place to keep shopping cart data. You can, of course, keep the data on the client's browser, but it can get pretty cumbersome trying to keep up with the shopping cart on the client when the user goes from page to page.

You can also store the shopping cart in a database and just keep enough data in the session to make it possible to retrieve the shopping cart out of the database. If the database is fast enough and you have so many sessions active at one time that you can't keep all the data in memory, the database might be a better solution. For most applications, however, the session is the ideal place.

When designing applications, it's often best to focus on the model portion of the application first. In other words, create Java classes that implement the behavior of the shopping cart. These classes should have no relationship to servlets or JSPs. You should be able to use them in an entirely different kind of application if you want to.

Here is a very good tutorial

Upvotes: 2

Related Questions