Write a program for authentication, which validate the login-id and password by the Servlet code

 Program :


Index.html:


<html>

<head>

<title>Login Page</title>

</head>

<body>

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

Enter Login ID: <input type="text" name="lid"><br>

Enter password: <input type="password" name="pass"><br><br>

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

</form>

</body>

</html>


LoginServlet.java :


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 LoginServlet extends HttpServlet 

{

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException 

{

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

PrintWriter out = response.getWriter();

String loginid = request.getParameter("lid");

String pass = request.getParameter("pass");

if(loginid.equals("TwosideTutorial") && pass.equals("TST12345"))

out.println("<h3>Login Successful!");

else

out.println("<h3>Login FAILED!");

}

}


Write a program for authentication, which validate the login-id and password by the Servlet code



1 Comments

Previous Post Next Post