Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Create Servlet Program using post method using HTML Form

Step-1st:-  Create Servlet and Define doGet() and doPost()

Step-2nd:  Design Form  under doGet() and Write Action Code under doPost()

Step3rd:-  Code of doGet():-

 public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
           PrintWriter out = response.getWriter();
           out.write("<form action='' method='post'>");
           out.write("<input type='text' name='txtnum1' placeholder='enter P' /><br><br>");
           out.write("<input type='text' name='txtnum2' placeholder='enter R' /><br><br>");
           out.write("<input type='text' name='txtnum3' placeholder='enter T' /><br><br>");
           out.write("<input type='submit' name='btnsubmit' value='click' />");

Step4th:-  code of doPost():-

 public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException
        PrintWriter out = response.getWriter();
        float p,r,t,si;
        p = Float.parseFloat(request.getParameter("txtnum1"));
        r = Float.parseFloat(request.getParameter("txtnum2"));
        t = Float.parseFloat(request.getParameter("txtnum3"));
        si = (p*r*t)/100;
       // out.print("Result is "+si);


    Code to display output in textfield  :-\

               out.print("<input type='text' value='"+request.getParameter("q")+"'/>");

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post