Preview:
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/formreqres")
public class formreqres extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public formreqres() {
        super();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Retrieve form data from the request
        String username = request.getParameter("username");
        String email = request.getParameter("email");

        // Set response content type
        response.setContentType("text/html");

        // Write the response
        try (PrintWriter out = response.getWriter()) {
            out.println("<html>");
            out.println("<head><title>Form Response</title></head>");
            out.println("<body>");
            out.println("<h1>Form Submission Details</h1>");
            out.println("<p><strong>Username:</strong> " + username + "</p>");
            out.println("<p><strong>Email:</strong> " + email + "</p>");
            out.println("</body>");
            out.println("</html>");
        }
    }
}


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Form Submission</title>
</head>
<body>
    <h1>Submit Your Details</h1>
    <form action="formreqres" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>
        <br><br>
        
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required>
        <br><br>

        <button type="submit">Submit</button>
    </form>
</body>
</html>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter