iForeRunner
 
   
 
  JAVA  
   
   
   
 
  Simple Form Submission in JSP | Example  
 
 
Simple form fields in JSP
Printing form variables in a JSP


1) Create a HTML page with following code and save as example.html

<html>
<head>
<title>forms</title>
</head>
<body>
<p>Below is an example for how to submit form field values to a JSP and print them.<br>
</p>
<form action="FirstForm.jsp">

<table>
<tbody>
<tr>
<td>Firstname</td>
<td>:</td>
<td><input type="text" name="firstname" size="20"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input type="text" name="lastname" size="20"></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><textarea rows="2" cols="20" name="address"></textarea></td>
</tr>
<tr>
<td>City</td>
<td>:</td>
<td><input type="text" name="city" size="20"></td>
</tr>
<tr>
<td>State</td>
<td>:</td>
<td><input type="text" name="state" size="20"></td>
</tr>
<tr>
<td>Zip</td>
<td>:</td>
<td><input type="text" name="zip" size="20"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="submit" value="Submit"> <input
type="reset" value="Reset"></td>
</tr>
</tbody>
</table>
</form>

</body>
</html>

Step 2) Write a JSP name it as FirstForm.jsp File name: FirstForm.jsp Following is JSP code:


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>FirstForm</title>
</head>
<body>
<%
String lastname= request.getParameter("lastname");
String firstname= request.getParameter("firstname");
String city= request.getParameter("city");
String address= request.getParameter("address");
String state= request.getParameter("state");
String zip= request.getParameter("zip");



%>

<p><br>You have submitted</p>
<table>

<tbody>
<tr>
<td>Firstname</td>
<td>:</td>
<td><%=firstname %></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><%=lastname %></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><%=address %></td>
</tr>
<tr>
<td>City</td>
<td>:</td>
<td><%=city %></td>
</tr>
<tr>
<td>State</td>
<td>:</td>
<td><%=state%></td>
</tr>
<tr>
<td>Zip</td>
<td>:</td>
<td><%=zip %></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>



Please send comments to vgdarur.javafive@blogger.com

 
     
 
 
 
http://www.iforerunner.com/