<html>

    <head>

        <title>Factorail  program for Servlet</title>

        

    </head>

    <body>

        <form action="http://localhost:8080/ServletPrograms/LoginServlet" method="post">

            enter User Name:

            <input type="text" name="t1" >

            <br>

            enter Password : 

            <input type="text" name="t2" >

            <br>

            <input type="submit" >

        </form>

    </body>

</html>

output:


source file name: LoginServlet.java


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(urlPatterns = {"/LoginServlet"})
public class LoginServlet extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            String  s1=request.getParameter("t1");
            String  s2=request.getParameter("t2");
            out.println("User Name is: "+s1);
            out.println("<br> Password  is: "+s2);
        }
    }

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

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

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

output: