Hi,
How can you make 2 different submit buttons request different Servlets in
the same form tag in a html file? For i.e if it looks something like this:
<form method="post" action="/Servlet1">
<input name="button1" type="submit" value="openServlet1">
<input name="button2" type="submit" value="openServlet2">
</form>
As you see i want one button to request one Servlet and the other button
an other servlet. But my form tags just point to one Servlet. Can this be
done without making a new form tat in the same html file.
Regards
John
Chris Smith - 11 Dec 2005 05:46 GMT
> <form method="post" action="/Servlet1">
> <input name="button1" type="submit" value="openServlet1">
[quoted text clipped - 4 lines]
> an other servlet. But my form tags just point to one Servlet. Can this be
> done without making a new form tat in the same html file.
The easiest option would be to point to one servlet, and have that
servlet examine the parameter names and then forward, using
RequestDispatcher. There are other options, such as using servlet
filters, but they would become more complicated.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Tim B - 11 Dec 2005 06:46 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Regards
> John
This could be done with javascript, with the onclick() event of each button,
by changing the form's action depending on the button clicked. However, you
would have to deal with form submission occurring when the user hits the
enter key, which may work differently in different browsers.
Real Gagnon - 11 Dec 2005 23:31 GMT
> How can you make 2 different submit buttons request different Servlets
> in the same form tag in a html file? For i.e if it looks something
[quoted text clipped - 4 lines]
><input name="button2" type="submit" value="openServlet2">
></form>
( from : http://www.rgagnon.com/jsdetails/js-0018.html )
<SCRIPT>
function submitFunction(i) {
if (i==1) document.theForm.action=
"http://www.company.com/cgi-bin/cgi1.cgi";
if (i==2) document.theForm.action=
"http://www.company.com/cgi-bin/cgi2.cgi";
if (i==3) document.theForm.action=
"http://www.company.com/cgi-bin/cgi3.cgi";
document.theForm.submit()
}
</SCRIPT>
<FORM NAME="theForm">
<INPUT TYPE="button" VALUE="Submit 1" onClick="submitFunction(1)">
<INPUT TYPE="button" VALUE="Submit 2" onClick="submitFunction(2)">
<INPUT TYPE="button" VALUE="Submit 3" onClick="submitFunction(3)">
</FORM>
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html