Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to do these?

Posted on 2001-06-21
4
Medium Priority
?
201 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

772 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