0

This is a servlet application for entering user name and password to validate a print in console weather log in successful or not. Please help me with the code. when I enter "abc" as user name I needed to get LOG IN SUCESSFULL. but my console says LOG IN FAILD. WHAT is wrong in my code? HTML CODE saved as index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>home page</title>
</head>
<body>


<h1>ABC Cinema</h1>

<form action="login" method="post">
<label>User Name:</label>
<input type="text" name="username"><br>
<label>Password:</label>
<input type="password" name="pswd"><br>
<input type="submit">
</form>

</body>
</html>

Servlet Code:


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/login")
public class Servlet1 extends HttpServlet{
   

   public void service(HttpServletRequest req,HttpServletResponse res)     //httpservletrequest is an object fom tomcat file
   {
       String userName=String.valueOf(req.getParameter("username"));
       String password=req.getParameter("pswd");
       
       
       System.out.println(userName);
       
       if(userName=="abc") {
           System.out.println("LOG IN SCUCCESSFUL");
       }
       else {
           System.out.println("LOG IN FAILD");
       }
   
   }
   }

What us Wrong in the CODE? When I write abc as username it says LOG iN FAILD???

V V ARJUN
  • 3
  • 3

0 Answers0