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().
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.