Write a program to develop JSP to get and display value from an HTML page.

Write a program to develop JSP to get and display value from an HTML page.

Write a program to develop JSP to get and display value from an HTML page.

1. Create the HTML Page (form.html)

This HTML page will have a form where users can enter data (e.g., their name), and submit it to the JSP page.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSP Input Form</title>
</head>
<body>
    <h2>Enter Your Name</h2>
    <form action="display.jsp" method="GET">
        <label for="name">Name: </label>
        <input type="text" id="name" name="name" required>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

2. Create the JSP Page (display.jsp)

This JSP file will receive the data submitted from the HTML form and display the value.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSP Display Value</title>
</head>
<body>
    <h2>Received Information</h2>
    <p>
        <strong>Name: </strong> 
        <%= request.getParameter("name") %>
    </p>
</body>
</html>

How It Works:

  1. HTML Page (form.html):
    • The user enters their name into the input field and submits the form.
    • The form sends the data via the GET method to display.jsp.
  2. JSP Page (display.jsp):
    • The request.getParameter("name") method retrieves the value of the name parameter sent by the HTML form.
    • The retrieved value is displayed on the page using the <%= %> scriptlet, which outputs the result to the browser.