aspose file tools*
The moose likes Servlets and the fly likes calling two servlets from different two Buttons In One Html Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling two servlets from different two Buttons In One Html Page" Watch "calling two servlets from different two Buttons In One Html Page" New topic
Author

calling two servlets from different two Buttons In One Html Page

bujjib babu
Greenhorn

Joined: May 31, 2006
Posts: 3
I am Having two buttons in my html page.

One is Add.
Second One is Delete.

When I press Add Button it should call AddServlet and when i press Delete button it should call DeleteServlet..

Please Justify me,..

Thanks..
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by bujjib babu:
I am Having two buttons in my html page.

One is Add.
Second One is Delete.

When I press Add Button it should call AddServlet and when i press Delete button it should call DeleteServlet..

Please Justify me,..

Thanks..


Initially, you send your both the request to the same servlet (controller) then here you check what request it is, (one way is, give any value to button and then compare here...) and do whatever you want to do...



This is the simplest solution of your problem. I guess.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Or you could use Javascript to set the action of your form when you click one of the buttons.


[My Blog]
All roads lead to JavaRanch
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Call doAdd() of JavaScript on click of Add button.
In doAdd()
document.form.action = �path of AddServlet�
document.form.submit();

Call doDelete() of JavaScript on click of Delete button.
In doDelete()
document.form.action = �path of DeleteServlet�
document.form.submit();


My blood is tested +ve for Java.
bujjib babu
Greenhorn

Joined: May 31, 2006
Posts: 3
Thanks for Reply..

Best Suggestion is JavaScript.. Its Working...

Bye
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Best Suggestion is JavaScript.. Its Working...
...yes, until a client has JavaScript disabled, then either nothing will happen or your application will get confused. I try to avoid JavaScript whenever there is a more robust alternative (using plain (X)HTML/XML and server technologies), and always try to take as much responsibility away from the client as possible (especially due to cross-browser incompatibilities).

So if your application is to be used flexibly, I would suggest finding an alternative to JavaScript, or at least making provisions for if it is disabled.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calling two servlets from different two Buttons In One Html Page