Wednesday, 3 May 2023

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.

 login.jsp

<%@ page language="java"%>

 <html>

 <body>

    <% String username = request.getParameter("username");

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

       if (username != null && password != null && username.equals(password)) { %>

            <h1>Login Successfully</h1>

       <% } else { %>

            <h1>Login Failed</h1>

       <% } %>

</body>

</html>

 

login.html

 <html>

<body>

    <form action="login.jsp" method="post">

        <label for="username">Username:</label>

        <input type="text" id="username" name="username" required><br>

        <label for="password">Password:</label>

        <input type="password" id="password" name="password" required><br>

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

    </form>

</body>

</html>