• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Click on the button

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i click on the button remove(<input type=button value='Remove'> , how can i call the method in the same class as the remove button.

And how can i clear all the product in a shopping cart.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nico Yukiko:

And how can i clear all the product in a shopping cart.


How did you put them in there in the first place?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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().
 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to link it to the remove method in that class
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is that what you were looking for?
 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nico,

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic