//form.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Input Form</title> </head> <body> <h2>Enter Your Details</h2> <form action="process.jsp" method="post"> <label for="name">Name:</label><br> <input type="text" id="name" name="name" required><br><br> <label for="email">Email:</label><br> <input type="email" id="email" name="email" required><br><br> <input type="submit" value="Submit"> </form> </body> </html> //process.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Form Submission Result</title> </head> <body> <h2>Submitted Details</h2> <% // Access request parameters using request.getParameter() String name = request.getParameter("name"); String email = request.getParameter("email"); // Check if parameters are not null (useful for handling cases when accessed directly) if (name != null && email != null) { %> <p><strong>Name:</strong> <%= name %></p> <p><strong>Email:</strong> <%= email %></p> <% } else { %> <p style="color:red;">No data received!</p> <% } %> <br> <a href="form.jsp">Go Back</a> </body> </html>
Preview:
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