Here we will discuss about the getParameter() method of the request object and how it is used in a JSP application.

getParameter() method of the Request Object gets value of the HTML form fields. These fields are linked with the form of a HTTP request. getParameter() method is used in Servlet and in JSP. In JSP request is the implicit object and can be used directly to get the parameter's value. In Servlet, it can be used by creating a reference variable of ServletRequest or HttpServletRequest interface. This method returns a string type value if requested parameter exists or returns null if they don't. Here we are discussing its use in a JSP application with examples.


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

Above syntax determines that the value of the attribute "id" of the form is assigning to the String type variable "Name".

Code of GetParameterMethodOfRequest.html:

This code creates a form in which one has to enter the username and password, which are then retrieved using getparameter() method.

<head><title>getParameter() method of request object.</title></head>
<form action="GetParameterMethodOfRequest.jsp" method="post">
<table border="0" cellspacing="0" cellpadding="0">
<td>User Name: </td>
<td><input type="text" size="20" name="txtUserName" />
<td>Password: </td>
<td><input type="password" size="20" name="txtPassword" />
<td> </td>
<td><input type="submit" value="Submit" name="B1" /></td>

Code of the GetParameterMethodOfRequest.jsp:

<%@page import="java.util.*" %><%
String username, password;
if(request.getParameter("txtUserName") == null)
username = "";
username = request.getParameter("txtUserName");
if(request.getParameter("txtPassword") == null)
password = "";
password = request.getParameter("txtPassword");
<table align="center" bgcolor="ffff00" border="1" cellspacing=
"0" cellpadding="0">
<td align><b>Your User Name: </b></td>
<td><%=username %><br/></td>
<td><b>Your Password: </b></td>
<td><%=password %></td>





We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+


Posted on: October 5, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: getparameter  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image