This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Servlets are Request/Response driven, they recieve a request, process it, then send a response.
To respond to the action you would need to cause make it send a request to the server. The simplest way is to make it a link, <a href="myServlet?action=Remove"> then respond to this on the server and send a response.
And how can i clear all the product in a shopping cart.
If you have added the individual items as, say, Java Beans, then you can identify them with some id (say, itemid) and remove it.
One of the simplest way to implement shopping cart is to put a List in the Session object. Clear all contents in this List, or, if you want to remove any/all reference of this user's purchase, make the List object null. If you want the session to end, call invalidate().
Why should i put the invalidate?? And to call it? if i place the code below in a shoppingCart servlet send.println( "<input type='button' name='empty' value='Empty Cart'> ");
And if i store the item brought in the linklist how can i empty all the things when it goes to another class?
Joined: Sep 11, 2005
1. I am sure you will have a submit button for purchasing an item. If the user clicks on it, you are going to retrieve the item's info (say item id) and store it in a String or Java Bean, say, and add it to the LinkedList. (This List will be present in the HttpSession object corresponding to this user. This Session will be the common share area where you can store the List.)
2. When the user clicks on the "Empty Cart" button, you will get this list from the Session and call clear() method on the List. This will clear all the contents in the list.
3. invalidate() should be called when the user logs out, so the session is destroyed.