Jsp Tutorial Home

Jsp Home

JSP Resources

Community

Site

The previous section has explained what all controls are used in HTML for creating the forms. Lets see with the help of below example how do we get the form data in JSP page which is send by the user.


We need to first define which JSP page should be accessed when this form is submitted. This can be achieved by the action attribute in the <form>. For example:- <form action="/login.jsp"> will generate a request for the login.jsp page when the submit button will be clicked for the form.


We will be creating the input1.jsp file which will show the data which user has sent from login.html page from the previous example.


Example:-









<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>


<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Login Form</title>

</head>


<body>


<p align="left"><b>Login Form


</b></p>


<form method="POST" action="login.jsp" name="loginForm">


<table border="1" width="50%" cellspacing="1" cellpadding="0" id="table1">

<tr>

<td width="50%">&nbsp;Login Name</td>

<td><input type="text" name="loginName" size="20"></td>

</tr>

<tr>

<td width="50%">Password</td>

<td><input type="password" name="password" size="20"></td>

</tr>

</table>

<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>

</form>


</body>


</html>



JSP page:-









<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Login Form Data</title>

</head>

<body>

<b>Submitted Values are </b>

<table border="1" width="50%" cellspacing="1" cellpadding="0" id="table1">

<tr>

<td width="50%">&nbsp;Login Name</td>

<td><%=request.getParameter("loginName") %></td>

</tr>

<tr>

<td width="50%">Password</td>

<td><%=request.getParameter("password") %></td>


</tr>

</table>

</body>

</html>



Output:- The following screen will be displayed when login form will gets submitted.


                    

Copyright © 2010 VisualBuilder. All rights reserved