Sunday, 11 March 2018

Servlet to Test Login Page


1.Statement of the problem

Java Servlet Program to Verify User Name and Password

2.Analysis

Problem consist of two tier Architecture client and serverClient enters his user name and password request is been sent to server.

Server accepts the request and request is farwarded to servlet container and container picks the particular servlet.

Servlet verifies user name and password and display message if user name and password correct else display invalid user name and password.


3.Design


4.Implementation

I).HTML program to display the User Name and Password.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Login Page using servlets</h1>
        <form action="NewServlet" method="GET" >
            <h3>Enter the user Name:<input type="text" name="u1" ></h3>
            <h3>Enter the Password:<input type="text" name="p1" ></h3><br/>
        <input type="submit" value="ClickHere"/>
        </form>
    </body>
</html>

II) Servlet Program it verifies the username and password to display successful message if both username and password are correct other wise it display a message username and password are not correct.
package abc;

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 NewServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
       String uname=request.getParameter("u1");
       String passwd=request.getParameter("p1");
       if(uname.equals("kumar")&& passwd.equals("kumar123"))
       {
       out.println("<h1>Logged in Successfully"+"</h1>");
       }
       else
       {
       out.println("<h1>wrong Username OR password!!!!!!"+"</h1>");
       }
     
    }
}

III) SCREEN SHOTS

i) Enter the User Name and Password


ii)When Username and password correct ie kumar and kumar123



iii)When Username and Password are not corect



No comments:

Post a Comment

PUBLISHER & SUBSCRIBER PATTERN

Using the UML Drawing Tool by implementing the code in Java demonstrate the Observer  Design Pattern. The Publisher-Subscriber desig...