0% found this document useful (0 votes)
10 views

Servlet.java

The document contains a Java program that demonstrates the use of Servlets by creating a student registration form in HTML and processing the submitted data using a servlet. The form collects various student details such as name, date of birth, gender, email, phone number, address, city, state, country, major, and enrollment interests. Upon submission, the servlet retrieves and displays the submitted information in a formatted HTML table.

Uploaded by

chetansalunke717
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)
10 views

Servlet.java

The document contains a Java program that demonstrates the use of Servlets by creating a student registration form in HTML and processing the submitted data using a servlet. The form collects various student details such as name, date of birth, gender, email, phone number, address, city, state, country, major, and enrollment interests. Upon submission, the servlet retrieves and displays the submitted information in a formatted HTML table.

Uploaded by

chetansalunke717
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/ 10

Name:- Shaikh Arshad Shaikh Idris

Class:-MCA ROLL NO:-168

Practical Name: Write a Java program(s) that demonstrates use of Servlets.

___________________________________________________________________

<!DOCTYPE html>

<!--

To change this license header, choose License Headers in Project Properties.

To change this template file, choose Tools | Templates

and open the template in the editor.

-->

<html>

<head>

<title>Student Registration Form</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<center>

<font color="red" size="7">

<marquee loop="3"> Fill form Carefully</marquee></font>

<h1>Student Information Form</h1>

<hr>

<form action="pract">

<div>

<label for="FirstName"> First Name:</label>

<input type="text" name="firstName" required>

</div>
<br>

<div>

<label for="LastName"> Last Name:</label>

<input type="text" name="lastName" required>

</div>

<br>

<div>

<label for="dateOfBirth">Date of Birth:</label>

<input type="date" id="dateOfBirth" name="dateOfBirth">

</div>

<br>

<div>

<label for="gender">Gender:</label>

<input type="radio" id="male"name="gender" Value="male">

<label for="male">Male</label>

<input type="radio" id="female"name="gender" Value="female">

<label for="female">Female</label>

<input type="radio" id="other"name="gender" Value="other">

<label for="other">Other</label>

</div>

<br>

<div>

<label for="email">Email:</label>

<input type="email" id="email" name="email" required>

</div>

<br>

<label for="phone">Phone Number:</label>

<input type="tel" id="phone" name="phone">


<div>

<br>

<div>

<label for="address">Address:</label>

<textarea id="address" name="address" rows="3"></textarea>

</div>

<br>

<div>

<label for="city">City:</label>

<input type="text" id="city" name="city">

</div>

<br>

<div>

<label for="state">State:</label>

<input type="text" id="state" name="state">

</div>

<br>

<div>

<label for="country">Country:</label>

<select id="country" name="country">

<option value="" selected disabled>Select Country</option>

<option value="India">India</option>

<option value="New Zeland">New Zealand</option>

<option value="Australia">Australia</option>

<option value="South Africa">South Africa</option>

</select>

</div>

<br>
<div>

<label for="major">Major/Course:</label>

<input type="text" id="major" name="major">

</div>

<br>

<div>

<label for="enrollmentData">Enrollment</label>

<textarea id="interests" name="interests" rows="3"></textarea>

</div>

<br>

<button type="submit">Submit Information</button>

<button type="reset">Reset</button>

<button type="cancel">Cancel</button>

</form>

</center>

</body>

</html>

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
/**

* @author gaura

*/

@WebServlet(urlPatterns = {"/pract"})

public class pract extends HttpServlet {

/**

* Processes requests for both HTTP <code>GET</code> and <code>POST</code>

* methods.

* @param request servlet request

* @param response servlet response

* @throws ServletException if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

try (PrintWriter out = response.getWriter()) {

/* TODO output your page here. You may use following sample code. */

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

out.println("<html>");

out.println("<head>");

out.println("<title>Servlet pract</title>");

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

out.println("<body><centre>");
out.println("<h1>Student Data</h1>");

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

out.println("<tr><td>");

out.println("<lable>First Name:-</lable>");

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

out.println("<td>");

out.println(request.getParameter("firstName"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<lable>Last Name:-</lable>");

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

out.println("<td>");

out.println(request.getParameter("lastName"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<lable>Date of Birth:-</lable>");

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

out.println("<td>");

out.println(request.getParameter("dateOfBirth"));

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

out.println("/tr");
out.println("<tr><td>");

out.println("<lable>Gender:-</lable>");

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

out.println("<td>");

out.println(request.getParameter("gender"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<label>Email id:-</label>");

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

out.println("<td>");

out.println(request.getParameter("email"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<label>Phone Number:-</label>");

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

out.println("<td>");

out.println(request.getParameter("phone"));

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

out.println("/tr");
out.println("<tr><td>");

out.println("<label>Address:-</label>");

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

out.println("<td>");

out.println(request.getParameter("address"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<label>City:-</label>");

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

out.println("<td>");

out.println(request.getParameter("city"));

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

out.println("/tr");

out.println("<tr><td>");

out.println("<label>State:-</label>");

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

out.println("<td>");

out.println(request.getParameter("state"));

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

out.println("/tr");
out.println("<tr><td>");

out.println("<label>Country:-</label>");

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

out.println("<td>");

out.println(request.getParameter("country"));

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

out.println("/tr");

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

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

out.println("index.html");

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

@Override

public String getServletInfo() {

return "Short description";

}
}

OUTPUT:-

You might also like