getParameterNames() Method Of The Request Object

This section gives you the detailed explanation about the getParameterNames() method of the request object.

getParameterNames() Method Of The Request Object

Example of getParameterNames() Method Of The Request Object in a JSP page.

     

This section gives you the detailed explanation about the getParameterNames() method of the request object. You will learn more about the procedure of using the getParameterNames() method of the request object. Why the method used and how to use? All the things about the getParameterNames() method is explained in this section which facilitates you for working with the method in efficient manner.

This is the method of the request object used for getting the enumeration of the attributes of the html form. These values are later retrieved through the java programming language by enumerating the retrieved enumerated data by the method of the request object.

This section provides JSP file which complete code is given below, provides the facility of getting all the attribute name of the html form. When you will submit the html form, JSP code executes and shows all the parameter name from the query string by using the method getParameterNames() of the request object.

Syntax of the method is as follows:

Enumeration e = request.getParameterNames();

Above line of the code store the retrieved data (in the enumeration form) through the getParameterNames() method of the request object to the Enumeration type variable e.

Here is the JSP code of the GetParameterNamesMethod.jsp file:

<%@page import="java.util.*" %>
<html>
	<head><title>getParameterNames() method of request object.</title>
</head>
	<body>
		<form 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>
		<%
			String ParameterNames = "";
			for(Enumeration e = request.getParameterNames();
 e.hasMoreElements(); ){
				ParameterNames = (String)e.nextElement();
				out.println(ParameterNames + "<br/>");
			}
		%>
	</body>
</html>

Output for the above code:

Download the GetParameterNamesMethod.jsp file.