Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
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.

 

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.

                         

» View all related tutorials
Related Tags: c io sed page tag if for example to exam ci e use in m ad age xa xamp s

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

4 comments so far (
post your own) View All Comments Latest 10 Comments:

i would like to ask how to remove space when getting parameters. for example

Posted by kim on Sunday, 08.3.08 @ 20:41pm | #70778

Extrimly Good

Posted by mayank shringi on Wednesday, 11.28.07 @ 10:27am | #40783

hai .......Ajay Anand,

I am krishna.
using getParamater() in HttpRequestServelt in servelt.
u can retrive the data from html form to ActionServet.
Example:
========
<input name=text name="username">
Servelt:
=========
import javax.servlet.http.*;
in servelet..we will retrive the data using getParameter()

username=request.getParameter("username");



Bye.....Ajay Anand
Krishna

Posted by krishna on Friday, 02.2.07 @ 17:12pm | #5462

How to retrive values from an html file through servlet.Mainly of the combobox.

Posted by Ajay Anand on Saturday, 01.27.07 @ 12:51pm | #4478

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.