Multiple Forms in JSP

The form tag creates a form for user input. A form can contain checkboxes, textfields, radio- buttons and many more. Forms are used to pass user- data to a specified URL which is specified in the action attribute of the form tag.

Multiple Forms in JSP

Multiple Forms in JSP

        

The form tag creates a form for user input. A form can contain checkboxes, textfields, radio- buttons and many more. Forms are used to pass user- data to a specified URL which is specified in the action attribute of the form tag. For the browser it is important to know where to send the request and how to send the request. To help the browser, form tag provides two attributes, first is action: Here is the address of the jsp page or any other page where the request will go. Second is the method, which tells which method is the browser using for sending the request. The methods are mainly the get and post.

 

The code of the program is given below:

 

 

<html>
  <head>
  <title>Using Multiple Forms</title>
  </head>
  <body>
  <h1>Using Multiple Forms</h1>
  <% 
  if(request.getParameter("button") != null) {
  %>
  You clicked 
  <%= request.getParameter("button") %>
  <%
  }
  %>
  <form name="form1" method="get">
  <input type="hidden" name="button" value="button 1">
  <input type="submit" value="Button 1">
  </form>
  <form name="form2" method="get">
  <input type="hidden" name="button" value="button 2">
  <input type="submit" value="Button 2">
  </form>
  <form name="form3" method="get">
  <input type="hidden" name="button" value="button 3">
  <input type="submit" value="Button 3">
  </form>
<form name="form4" method="get">
  <input type="hidden" name="button" value="button 4">
  <input type="submit" value="Button 4">
  </form>
<form name="form5" method="get">
  <input type="hidden" name="button" value="button 5">
  <input type="submit" value="Button 5">
  </form>
  </body>
</html>

The output of the program is given below:

The output of this form will be:

Download this example.