JSP Form Processing Using GET Method

The GET method is one of the HTTP methods used to send form data to a web server. When this happens, the form is submitted using the GET method and the form data is inserted into the query parameters of the URL.

Step-by-Step implementation of GET Method

Step 1: Create the dynamic web project using eclipse and its project named as jsp-GET-demo.

Note: If you beginner click here to know the process of creating the dynamic web project.

Step 2: After creating a JSP form named index.jsp and this form includes input fields to store user data and the form attributes can be set on the JSP page to customize the form to be submitted and set the method attribute enter “GET”.

HTML
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>GET Form Processing</title>
    <style>
        /* CSS styles for better visibility */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
        }

        .container {
            width: 50%;
            margin: 50px auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        h2 {
            color: #333;
            text-align: center;
        }

        form {
            margin-top: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        input[type="text"],
        input[type="email"],
        input[type="submit"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-sizing: border-box; /* Ensure padding and border are included in width */
        }

        input[type="submit"] {
            background-color: #007bff;
            color: #fff;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Submit Form (GET Method)</h2>
        <form action="processGet.jsp" method="GET">
            <label for="name">Name:</label>
            <input type="text" id="name" name="name" required><br>
            <label for="email">Email:</label>
            <input type="email" id="email" name="email" required><br>
            <input type="submit" value="Submit">
        </form>
    </div>
</body>
</html>


Step 3: Create a new JSP page and name it processGet.jsp which processes the submission process and retrieves the form data from the request object using the getParameter() method on this page. This method can name the form field as its parameter and return the value entered by the user.

HTML
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>GET Form Processing</title>
    <link rel="stylesheet" type="text/css" href="WEB-INF/css/style.css">
    <style>
        /* Additional CSS for better visibility */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
        }

        .container {
            width: 50%;
            margin: 50px auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        h2, h3 {
            color: #333;
            text-align: center;
        }

        p {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>GET Form Processing</h2>
        <%-- Retrieving parameters from the request --%>
        <% String name = request.getParameter("name"); %>
        <% String email = request.getParameter("email"); %>

        <h3>Hello, <%= name %></h3>
        <p>Your email is: <%= email %></p>
    </div>
</body>
</html>


Step 4: Once we complete the project, it runs the tomcat server then output shows the form. Refer the below output image for better understanding.

Output:

1. Display the Form

2. Display the processed Data:

JSP – Form Processing

In JavaServer Pages, Form processing is the fundamental aspect of web development, and it can allow users to interact with websites by submitting data. It can handle form submissions involving extracting the data from the HTTP requests and generating the appropriate responses.

Similar Reads

Form Processing in JSP

Form processing in the JavaServer Pages involves receiving data submitted through the HTML forms extracting this data from the request object and generating the response based on the received data....

JSP Form Processing Using GET Method

The GET method is one of the HTTP methods used to send form data to a web server. When this happens, the form is submitted using the GET method and the form data is inserted into the query parameters of the URL....

JSP Form Processing Using Post Method

Below is the step-by-step implementation of POST method....