Home Jsp getParameter() Method Of The Request Object
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

getParameter() Method Of The Request Object

Advertisement
This section illustrates you about the getParameter() method of the request object. This section provides you the best illustration for why the method used or how to use in your JSP application.

getParameter() Method Of The Request Object

     

This section illustrates you about the getParameter() method of the request object. This section provides you the best illustration for why the method used or how to use in your JSP application. You can directly copy the provide JSP code (provided in the section) and paste it into your JSP application for getting all the facilities provided by the getParameter() method of the request object.

This is the method, used for getting the value of the HTML form fields. This method returns the string type value i.e. the value of the specified field of an HTML form. This method takes a string type parameter which is the name of the attribute of the html which value has to be retrieved through the request object.

Syntax of the method:

String variableName = requset.getParameter("txtUserName");

Above syntax determines that the value of the attribute "txtUserName" of the html form field is assigning to the String type variable "variableName".

This section provides the complete code of two files which have been used in the section for the complete and best illustration of the method of the request object. These are as follows:

  • GetParameterMethodOfRequest.html
  • GetParameterMethodOfRequest.jsp

The html file constructs a form in which you have to enter the user name and password which is retrieved in the JSP page by using the getParameter() method of the request object.

Here is the complete code of GetParameterMethodOfRequest.html file:

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

Output for the GetParameterMethodOfRequest.html file:

Here is the complete JSP code of the GetParameterMethodOfRequest.jsp file:

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

Output for the GetParameterMethodOfRequest.jsp file:

Download GetParameterMethodOfRequest.html file

Download GetParameterMethodOfRequest.jsp file.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 12, 2008

Related Tutorials

Ask Questions?    Discuss: getParameter() Method Of The Request Object   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Spandana
June 7, 2012
Really Good

very nice article.. easy to understand. Thanks
kuman
August 3, 2012
getParameter() Method

how to retrive int value from html page....
Rifat
September 19, 2013
getParameter() Method Of The Request Object

Thanks a lot
sagar
November 11, 2013
getParameter() method of request object

It is very simple to understand. Really super......
DMCA.com