Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp JSP WITH MULTIPLE FORMS

Related Tutorials


 
 

Share on Google+Share on Google+

JSP WITH MULTIPLE FORMS

Advertisement
In this example, you will learn how to make multiple forms in single jsp page. Most of the times people need to use multiple forms on a single page. For example on one web page you may add forms for login, search and send link to friends.

JSP WITH MULTIPLE FORMS

     

In  this example, you will learn how to make multiple forms in single jsp page. Most of the times people need to use multiple forms on a single page. For example on one web page you may add forms for login, search and send link to friends.

Program Description:

These type of programs are almost used for performing specific operations on the the specific form data. This page submit only one form with it's data at a time.

Code Description:

We used html code and jsp tag to complete these Forms(Form1, Form2, Form3) that we have made on a single page. Here you will see how this program works. Suppose if you clicked on the button (labeled by "Form 1"), you will see the data of Form1. If you clicked on button (labeled by "Form 2") that is a field of second form in the document, you will see the data of  Form2. But there are three forms in the page and each form has a submit button with different label like "Form 1", "Form 2" and last one is the "Form 3" these have been used to navigate specific JSP page. To identify which form no. you clicked we have used getParameter() method of request object where form name has been passed and checked if this is not equal to null. If it is not, then show that You clicked this particular form. and the rest page is shown as it was earlier.

<HTML>
<HEAD>
<TITLE>JSP WITH  MULTIPLE FORMS</TITLE>
</HEAD>
     <body>
         <center>
         <table width="100%" border="1px" bordercolor="#000080" 
cellpadding="0" cellspacing="0" decolor=""#E2FEFD>
            <tr>
              <td><b><font size="5" color="#333399">JSP WITH
 MULTIPLE FORMS </font></b></td>
            </TR>
            <tr>
               <td height="47" valign="top" bgcolor="#E0EDFD">
                 <br>&nbsp;<b>
	         <%
		     if(request.getParameter("FormName") != null){
	         %>
		 You Clicked <%= request.getParameter("FormName") %>
	         <%}%></b>
                 &nbsp;</td>
             </tr>
             <tr>
               <td>
                  <FORM NAME="form1" METHOD="POST">
                     <INPUT TYPE="HIDDEN" NAME="FormName" VALUE="Form 1">
                     <br><INPUT TYPE="image" SRC="form1.gif">
                  </FORM>
                  <FORM NAME="form2" METHOD="POST">
                     <INPUT TYPE="HIDDEN" NAME="FormName" VALUE="Form 2">
	             <INPUT TYPE="image"  SRC="form-2.gif">
                  </FORM>
                  <FORM NAME="form3" METHOD="POST">
                     <INPUT TYPE="HIDDEN" NAME="FormName" VALUE="Form 3">
                     <INPUT TYPE="image"  SRC="form-3.gif">
                  </FORM>
               </td>
             </tr>
         </table>
         </center>
     </BODY>
</HTML>

OutPut of the Program:

You can download the example by clicking on the following link and copy and paste the complete folder in your webapps folder in TOMCAT after extracting the zip file. And you can run the example by typing the url : http://localhst:8080/JSPMultipleForms/CreatingMultipleForm.jsp .

Download This Example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 22, 2008

Related Tutorials

Discuss: JSP WITH MULTIPLE FORMS  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com