Solved

how to do these?

Posted on 2001-06-21
4
196 Views
Last Modified: 2010-03-31
hi
I'm working on a shopping cart and i'm facing the following problem.could anybody help.
i have a shop cart which shows some lists of products in a table .at the beginning of each row I have included a checkbox which the purchaser can click to indicate if he wants to delete it from the shopcart.how do i handle
A
1.if user clicks one checkbox and then presses a button  to delete.
 2.if the user clicks on more than one rows of products and clicks the delete button
B.After deletion the remaining items in the shopcart should be shown.

I'm working in servlets.the shopcart fethches data from a temporary database table which is updated on every addition/deletion.
could these things be done without major hassles through servletsand jdbc
0
Comment
Question by:ManojKumar
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 100 total points
ID: 6214065
You could use the putValue() and getValue() methods of HttpSession.
For example you could do it like this:

If the session is new add a Vector to it for storing items:
HttpSession sess = request.getSession();
if( sess.isNew() ) {
  sess.putValue( "items", new Vector() );
}

The if the user wants to add an item you add the item to the vector:
Item item = new Item( ... );  /your class for storing item infos
HttpSession sess = request.getSession();
Vector items = (Vector)sess.getValue( "items" );
items.addElement( item );

Or showing the iterms:
HttpSession sess = request.getSession();
Vector items = (Vector)sess.getValue( "items" );
for( int i=0; i<items.size(); ++i ) {
  Item item = (Item)itmes.elementAt(i);
  // print item here
}

When the customer clicks 'order' you store all the items in the database with
some additional infos, for ex. customer ID or name and addres or...
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6214075
If you use this session variables you won't get some zombie items in the
database when the customer didn't order, because the session gets a
timeout and the items in the session will be discarded.
0
 

Expert Comment

by:Nachiap
ID: 6215996
what you can do is just keep all the product details in one vector (probaly you can put it in some bean so that vector of productbean)
along with product id.
In the page give the check box name the same (ex : chk)& value as the product id (ex : productBean.getProductId()).
when that page is submited with some check boxes checked for deletion then u can get all the product ids to deleted
(tho request.getParameterValue())
now u can loop tho that & u can just remove that from the vactor in session.
finally update all the values in session to data base..

0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950877


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  Points to superschlonz


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question