Q. Write a JSP script to accept username and password from user, if they are same then display “Login Successfully” message in Login.html file, otherwise display “Login Failed” Message in Error.html file
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<h2>User Login</h2>
<form action="validate.jsp" method="post">
Username: <input type="text" name="username" required /><br><br>
Password: <input type="password" name="password" required /><br><br>
<input type="submit" value="Login" />
</form>
</body>
</html>
Validate.jsp
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username != null && password != null && username.equals(password)) {
response.sendRedirect("Login.html");
} else {
response.sendRedirect("Error.html");
}
%>
Login.html
<!DOCTYPE html>
<html>
<head>
<title>Login Success</title>
</head>
<body>
<h2 style="color:green;">Login Successfully</h2>
</body>
</html>
Error.html
<!DOCTYPE html>
<html>
<head>
<title>Login Failed</title>
</head>
<body>
<h2 style="color:red;">Login Failed</h2>
</body>
</html>
