Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Different buttons to request different Servlets.

Thread view: 
Luke - 11 Dec 2005 03:55 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.