Sunday, 25 March 2018

Servlet Program to demonstrate get and post



 Write a JAVA Servlet Program to implement and demonstrate Get() and Post() methods(Using HTTP Servlet Class).

// index.html

<html>
 <body>
    <form method="post" action="servlet3" >
     User name <input type="text" name="uname" />
     Password  <input type="password" name="pwd" />
     <input type="submit" value="Login" />
    </form>
 </body>
</html>

-------------------------------------------------------------------------
// servlet3

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class servlet3 extends HttpServlet
{
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
                response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String u=request.getParameter("uname");
            String p=request.getParameter("pwd");
        String valid=null;
        if((u.equals("admin")) && (p.equals("rose")))
           valid="Successful";
        else
               valid="Unsuccessful";
            out.println("<html>");
            out.println("<body>");
            out.println("<h1> Your authentication is "+valid+"</h1>");
            out.println("</body></html>");
    }



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


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...