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

Practical No 22

This document outlines a practical exercise to create a servlet program that handles user authentication via HTML forms. It includes an HTML form for username and password input, and a Java servlet that processes the input, providing feedback on login success or failure. The servlet checks for specific credentials and responds accordingly, demonstrating basic web application functionality.

Uploaded by

kaverinagare39
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)
2 views

Practical No 22

This document outlines a practical exercise to create a servlet program that handles user authentication via HTML forms. It includes an HTML form for username and password input, and a Java servlet that processes the input, providing feedback on login success or failure. The servlet checks for specific credentials and responds accordingly, demonstrating basic web application functionality.

Uploaded by

kaverinagare39
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/ 2

Practical No: 22

Title: Write A Servlet Program TO Send The Username And Password Using HTML , Forms And
Authrntication The User…………..
Batch : B Roll No : 47 Dop : 22/10/24

HTML PROGRAM :

<!DOCTYPE html>
<html>
<head>
<title>Servlet Program</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="MyServlet" method="get">
<label>Username:</label><input type="text" placeholder="Enter the Username"
name="user"> <br><br>

<label>Password:</label><input type="text" placeholder="Enter the Password"


name="pass"> <br><br>

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

</form>

</body>
</html>

OUTPUT :

SERVLET SERVER PROGRAM :

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class server extends HttpServlet


{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rep)
throws ServletException, IOException
{
rep.setContentType("text/HTML");
PrintWriter pw=rep.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("<title>MyTitleTrial</title>");
pw.println("</head>");
pw.println("<body>");
String user=req.getParameter("user");
String pass=req.getParameter("pass");
if(user.equals("") && pass.equals(""))
{
pw.println("<h1> Please Enter The UserName And Password!!!!!");
}

else
if(user.equals("Yash") && pass.equals("yash@123"))
{
pw.println("<h1>Login Successfull!!!!!!</h1>");
}

else
{
pw.println("<h1>Login Failed!!</h1><br>Please Enter The Proper User Name And
Password!!!");
}
pw.println("</body>");
pw.println("</html>");
}
}

OUTPUT :

You might also like