Solved

how to do these?

Posted on 2001-06-21
4
190 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility


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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now