Different buttons to request different Servlets.

L

Luke

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
 
C

Chris Smith

Luke said:
<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.

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Tim B

Luke said:
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
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.
 
R

Real Gagnon

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>

( 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top