Create a servlet for a login page. If the username and password are correct then it says message “Hello ” else a message “login failed”.

index.html

 <html> 

    <head> 

        <title>Login Form</title> 

    </head>  

    <form action="LoginServlet" >     

        Enter UserName :<input type="text" name="txtId"><br> <br>  

        Enter Password :<input type="password" name="txtPass"><br><br> 

        <input type="reset" value="Reset"> 

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

    </form> 

</html> 

CalculatorServlet.java

package mypack; 

import java.io.*;

import javax.servlet.ServletException; 

import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)              throws ServletException, IOException {               response.setContentType("text/html;charset=UTF-8");             PrintWriter out = response.getWriter(); 

         out.println("<html><head><title>Servlet LoginServlet</title></head>"); 

        String uname = request.getParameter("txtId");  

        String upass = request.getParameter("txtPass");            

        if(uname.equals("Rupam") && upass.equals("12345"))

        {      

            out.println("<body bgcolor=blue >");                   

            out.println("<h1> Welcome !!! "+uname+"</h1>");    

        }             

else         

        {     

            out.println("<body bgcolor=red >");             

            out.println("<h1> Login Fail !!! </h1>");  

        }       

        out.println("</body></html>");

    }

Output:-









Post a Comment

0 Comments