This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Click on the button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Click on the button" Watch "Click on the button" New topic
Author

Click on the button

Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
Sravan Kumar
Ranch Hand

Joined: Sep 11, 2005
Posts: 121
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().


keep smilin :: sravan<br /><a href="http://sravanpens.blogspot.com" target="_blank" rel="nofollow">I scribble here</a>
Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
How to link it to the remove method in that class
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459



Is that what you were looking for?
Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
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

Joined: Sep 11, 2005
Posts: 121
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Click on the button
 
Similar Threads
Deleting/removing JPanel
SET A BUTTON AS "DEFAULT"
Removing row from table
Space character in URL error when running midlet
remove cache from java code in jsp