0% found this document useful (0 votes)
8 views5 pages

Form Validation

The document contains an HTML form for entering student information, including fields for roll number, name, address, phone, and total marks. Upon submission, the data is processed by a servlet that generates an HTML response displaying the entered information. The form and servlet are designed to work together to collect and present student details in a user-friendly manner.

Uploaded by

22cs026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Form Validation

The document contains an HTML form for entering student information, including fields for roll number, name, address, phone, and total marks. Upon submission, the data is processed by a servlet that generates an HTML response displaying the entered information. The form and servlet are designed to work together to collect and present student details in a user-friendly manner.

Uploaded by

22cs026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Form validation

index.html

<!DOCTYPE html>

<html>

<head>

<title>Student Information Form</title>

</head>

<body bgcolor="violet">

<center>

<form method="post" action="NewServlet">

<h3>Enter Student Information</h3>

<table>

<tr>

<td><b>Roll Number</b></td>

<td><input type="text" name="Roll number" size="25"


value=""><br/></td>

</tr>

<tr>

<td><b>Student Name</b></td>

<td><input type="text" name="Student Name" size="25"


value=""><br/></td>
</tr>

<tr>

<td><b>Student Address</b></td>

<td><input type="text" name="Address" size="25"


value=""><br/></td>

</tr>

<tr>

<td><b>Phone</b></td>

<td><input type="text" name="Phone" size="25"


value=""><br/></td>

</tr>

<tr>

<td><b>Total Marks</b></td>

<td><input type="text" name="Total Marks" size="25"


value=""><br/></td>

</tr>

</table>

<br/>

<input type="submit" value="SUBMIT">

</form>

</center>
</body>

</html>

SERVLET PROGRAM

import jakarta.servlet.*;

import jakarta.servlet.http.*;

import java.io.*;

public class NewServlet extends HttpServlet {

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse


response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

// Get form parameters

String rollNumber = request.getParameter("Roll number");

String studentName = request.getParameter("Student Name");

String address = request.getParameter("Address");

String phone = request.getParameter("Phone");


String totalMarks = request.getParameter("Total Marks");

// Generate HTML response

out.println("<!DOCTYPE html>");

out.println("<html>");

out.println("<head>");

out.println("<title>Student Information Display</title>");

out.println("</head>");

out.println("<body bgcolor='violet'>");

out.println("<center>");

out.println("<h2>Student Information Details</h2>");

out.println("<table border='1' cellpadding='5'>");

out.println("<tr><th>Field</th><th>Value</th></tr>");

// Display student information

out.println("<tr><td><b>Roll Number</b></td><td>" + rollNumber +


"</td></tr>");

out.println("<tr><td><b>Student Name</b></td><td>" + studentName +


"</td></tr>");

out.println("<tr><td><b>Address</b></td><td>" + address +
"</td></tr>");
out.println("<tr><td><b>Phone</b></td><td>" + phone + "</td></tr>");

out.println("<tr><td><b>Total Marks</b></td><td>" + totalMarks +


"</td></tr>");

out.println("</table>");

out.println("<br/>");

out.println("<a href='index.html'>Back to Form</a>");

out.println("</center>");

out.println("</body>");

out.println("</html>");

out.close();

You might also like