getParameter() – Passing data from client to JSP

The familiarity of the getParameter() method in getting data, especially form data, from a client HTML page to a JSP page is dealt with here. The request.getParameter() is being used here to retrieve form data from client side.

Steps to be followed
1) First, a html page exGetParameter.html accepts data from the client. The client enters text in the space provided and clicks on ‘Submit’.
2) Immediately the getparam.jsp page gets called, it being mentioned in the action tag.
3) This JSP page fetches the data using getParameter() method and displays the same to the user.

Note: Entire application has been developed and tested on NetBeans IDE 8.1.

Page to accept client data : exGetParameter.html page

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
    <head>
        <title>Get Parameter Example</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,
                                       initial-scale=1.0">
    </head>
    <body>
        <!-- Here we specify that the from data will be sent to 
             getparam.jsp page using the action attribute  
        -->
        <form name="testForm" action="getparam.jsp">
           <label><h1>Enter a text and click Submit<h1/></label><br/>
           <input type="text" name="testParam"><br/>
           <input type="submit">
        </form>
    </body>
</html>

chevron_right


Page to fetch client data : getparam.jsp

filter_none

edit
close

play_arrow

link
brightness_4
code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;
                                            charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%-- Here we fetch the data using the name attribute 
             of the text from the previous page
        --%>
        <% String val = request.getParameter("testParam"); %>
    </body>
    <%-- Here we use the JSP expression tag to display value 
         stored in a variable
    --%>
    <h2>The text entered was : </h2><%=val%>
</html>

chevron_right


Outputs
Client Data : exGetParameter.html
Client Data

After clicking on ‘Submit’ the following screen appears.
Fetched Data from Client : getparam.jsp
Fetched Data from Client



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.