Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 11th, 2000, 03:02 PM
xtony xtony is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 xtony User rank is Private First Class (20 - 50 Reputation Level)xtony User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<form
name=form1
action="userActionServlet"
method="post"
>
//...
<input
type=submit
name=calculate
value="Calculate"
>
<input
type=submit
name=save
value=" Save "
>

If I intend to use my ActionServlet to
perform both 'calculate' and 'save'
functionalities, I need to know
which 'submit' button is hit. So,
How do I know which one is hit via
the 'name' property--or some other
way?

Is this possible?

OR, is it possible to associate
two servlets to two submit-buttons
for a single form?
It seems CGI guys do use two named
submit buttons with a single form.
Am I right in this?

Thanks in advance.



------------------
Regards,
Tony
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #2  
Old July 15th, 2000, 09:47 PM
OttoX OttoX is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Guayquil, Ecuador
Posts: 7 OttoX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi, the best solution i can think of is manipulating the form in the client side, by doing this:
two javascript functions to be called in the onclick event for each submit button.
As you can imagine if you click the first button you will get some values for the form fields (using hidden fields could be good idea) and if you click the second one you get other values, doing this the servlet will "know" wich submit has been clicked.
I think you can also select the "action" for the form dinamically with javascript, allowing this to use to different servlets.

An example function to manipulate form values is:
<input type=submit name=calculate value=""
onclick=calculate()>
<input type=submit name=save value=""
onclick=save()>
....
function calculate(){
document.formname.calculate.value="calculate";
//document.formname.submit
}
function save(){
document.formname.save.value="save";
//document.formname.submit
}
this code is not tested, but is something like that
Bye
Hope it helps.
OttoX



Reply With Quote
  #3  
Old July 17th, 2000, 12:45 PM
xtony xtony is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 xtony User rank is Private First Class (20 - 50 Reputation Level)xtony User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Ottox,

Thanks a lot to you for your answer which
sparked me into yet another solution
to my origninal question:

if I put

<form
name=form1
action="userActionServlet"
method="POST"
>
//...
<input
type=submit
name=submit
value="Calculate">
<input
type=reset
name=reset
value=Reset">
<input
type=submit
name=submit
value="Save">

then I can use

out.prinlnt("<BR>"+req.getParameter("submit")+"<BR>"));

to get the 'value' of the clicked submit
button. In such way, I can know which
submit-typed button is clicked and fire a
corresponding action inside the
ActionServlet.

Thank you again, Ottox. Keep cool!


------------------
Regards,
Tony

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > How to recognize two submit-typed buttons by name in a servlet?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway