In this Section, we will learn about using "getQueryString() " method to retrieve the 'query string'.
In this Section, we will learn about using "getQueryString() " method to retrieve the 'query string'.In this Section, we will learn about using "getQueryString() " method to retrieve the 'query string'.
The "getQueryString()" method is used to fetch the 'query string'. The query string contains the attribute & the value of the html or JSP form, which sends with the POST /GET method to Servlet or JSP page for any request.
Example : In this Example , we are asking user to enter any username and password string, the output displays the query string means username & password . The Query String is fetched using the method "getQueryString()".
<html> <head><title>getQueryString() method of request object.</title></head> <body bgcolor="purple"> <form method="get" > <table border="0" cellspacing="0" cellpadding="0"> <tr> <td><b><font color="white">User Name:</font></b> </td> <td><input type="text" size="20" name="txtUserName" /> </tr> <tr> <td><b><font color="white">Password: </font></b></td> <td><input type="password" size="20" name="txtPassword" /> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" name="B1" /></td> </tr> </table> </form> <font color="white"> <% if(request.getQueryString() != null) out.println(request.getQueryString()); %> </font> </body> </html> |
OUTPUT :
After Submitting Value the output should be :