SERVLET PROGRAM TO SEND USERNAME AND PASSWORD USING HTML FORMS AND AUTHENTICATE THE USER

 index.html


<html>

    <head>

        <title>User Authentication</title>

         <style>

            form{

            width: 50%;

            }

            legend {

                display: block;

                padding-left: 10px;

                padding-right: 10px;

                border: 3px solid green;

                background-color:tomato;

                color:white;;

            }

    </style>

    </head>

    <body>

        <div>

            <fieldset>

                <legend> DOODLE LOGIN ::</legend>

        <form  method="get" action="authservlet">

        <b>User Name: </b> <input type="text" name="uname"><br><br>

        <b>Password: </b> <input type="password" name="pswd"><br><br>

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

       

        </form>

             </fieldset>

        </div>

    </body>

</html>

authservlet.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 authservlet extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet authservlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet authservlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) { 
           String s1  = request.getParameter("uname"); 
           String s2  = request.getParameter("pswd"); 
           
           if ((s1.equals("gidol26654@rubeshi.com"))&& (s2.equals("cat"))){
           out.println("<br><br><br><br><br><center><h1>Login Successful !!!!<h1><center>");
           }else{
           out.println("<br><br><br><br><br><center><h1>Incorrect Entry -Try Again !!!!!<h1><center>");
        }
        } 
    }

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

   
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
OUTPUT:









No comments:

Post a Comment