The Wayback Machine - https://web.archive.org/web/20240625042506/https://www.geeksforgeeks.org/getparameter-passing-data-from-client-to-jsp/
Open In App

getParameter() – Passing data from client to JSP

Last Updated : 10 Jun, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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




<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>


Page to fetch client data : getparam.jsp




<%@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>


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



Similar Reads

getAttribute() - Passing data from Server to JSP
Suppose some data at the Server side has been created and now in order to pass that information in a JSP page, there is a need of request.getAttribute() method. This, in fact differentiates the getAttribute() and getParameter() methods. The latter is used to pass Client side data to a JSP. Implementation 1) First create data at the server side and
3 min read
JSP - Client Request
In web development, a Client Request refers to a connection sent from a client to a server to edit data, and objects, or to perform or receive operations. In the case of JavaServer Pages (JSP), client requests can be processed using JSP files and servlets running on the web server. In this article, we will learn how to create a Client Request Form
4 min read
Program to validate a user using JSP
Introduction to JSP : JSP(Java Server Page) is a server-side technology, used for developing webpages that support dynamic content. It enables the separation of dynamic and static content, thereby reducing development complexity. Developers are thus, armed with the power to insert java code in HTML pages by employing special JSP tags most of which
4 min read
Exception handling in JSP
Java Server Pages declares 9 implicit objects, the exception object being one of them. It is an object of java.lang.Throwable class, and is used to print exceptions. However, it can only be used in error pages. There are two ways of handling exceptions in JSP. They are: By errorPage and isErrorPage attributes of page directiveBy &lt;error-page&gt;
3 min read
Environment setup for JSP
The environment setup for JSP mainly consists of 3 steps: Setting up the JDK. Setting up the webserver (Tomcat). Starting tomcat server. All the steps are discussed in details below: Setting up Java Development Kit : Step 1: This step involves downloading JDK from Download JDK. Step 2: Setting up the PATH environment variable appropriately. For win
2 min read
Life cycle of JSP
A Java Server Page life cycle is defined as the process that started with its creation which later translated to a servlet and afterward servlet lifecycle comes into play. This is how the process goes on until its destruction. Following steps are involved in the JSP life cycle: Translation of JSP page to ServletCompilation of JSP page(Compilation o
2 min read
Difference between Servlet and JSP
Brief Introduction: Servlet technology is used to create a web application. A servlet is a Java class that is used to extend the capabilities of servers that host applications accessed by means of a request-response model. Servlets are mainly used to extend the applications hosted by web services. JSP is used to create web applications just like Se
3 min read
Directives in JSP
JSP directives are the elements of a JSP source code that guide the web container on how to translate the JSP page into its respective servlet. Syntax : &lt;%@ directive attribute = "value"%&gt; Directives can have a number of attributes that you can list down as key-value pairs and separate by commas. The blanks between the @ symbol and the direct
4 min read
JSP | Expression tag
Expression tag is one of the scripting elements in JSP. Expression Tag in JSP is used for writing your content on the client-side. We can use this tag for displaying information on the client's browser. The JSP Expression tag transforms the code into an expression statement that converts into a value in the form of a string object and inserts into
2 min read
JSP | Implicit Objects - request and response
Perquisite: Introduction To JSPJSP stands for Java Server Pages, and it's a server side technology. It's used for creating web applications and dynamic web content. The main property of JSP is that we can insert our java code inside our HTML page using JSP tag. JSP provides you platform-independent pages. C/C++ Code &lt;%@ page language = &quot;jav
4 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg