request.getParameter

We are going to learn about request.getParameter.The request.getParameter method of request object in JSP (java server page) application. In this method we have used for getting value of the HTML form fields and return the string type value.

request.getParameter

request.getParameter

We are going to learn about request.getParameter.The request.getParameter method of request object in JSP (java server page) application. In this method we have used for getting value of the HTML form fields and return the string type value. The request.getParameter method are takes a string type parameter in which the name of the attributes of the HTML which value has to be recalled through the request object. We can directly copy the provide JSP code  and paste it into your JSP application for getting all the facilities provided by the get Parameter() method of the request object.

Syntax of request.getParameter.

String variable Name = requset.getParameter("id");
String variable password = request.getParameter("psw");

We  create two fields in html page userid , password and submit button. In this form we have enter userid and password  which is  recalled in JSP page by using request.getParameter() method of the request object.

you can see below examples:

LoginForm.html

<%@ 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>request.getParameter</title>
</head>
<body>
<form action="LoginProcess.jsp" method="post">
<table align="center">

<tr>
<td colspan=2><center><font size=4><b>Login From</b></font></center></td>
</tr>
<tr>
<td>UserID</td>
<td><input type="text" size="30" name="id" /></td>
</tr>

<tr>
<td>Password</td>
<td><input type="password" size="30" name="psw"></td>
</tr>

<tr>
<td></td>
<td><input type="submit" value="Submit" ></td>
</tr>
</table>
</form>
</body>
</html>

LoginProcess.jsp

<%@page import="java.util.*"%>
<%
String userid, password;
if (request.getParameter("id") == null)
userid = "naulej";
else
userid = request.getParameter("id");
if (request.getParameter("psw") == null)
password = "naulej";
else
password = request.getParameter("psw");
%>
<table align="center" bgcolor="white" cellspacing="3" cellpadding="3">
<tr>
<td><b>User Name:</b></td>
<td><%=userid%><br />
</td>
</tr>
<tr>
<td><b>Password: </b></td>
<td><%=password%></td>
</tr>
</table>

Output:-

Download Source Code