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

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

How we take form input in servlet  :-

We can write HTML Element under Servlet tag using double quote and single quote.

public class SwapServlet extends HttpServlet {

   public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
       PrintWriter out = response.getWriter();
       out.write("<form action='#' method='get'>");
       out.write("<input type='text' name='txtnum1' placeholder='enter first number' /><br><br>");
       out.write("<input type='text' name='txtnum2' placeholder='enter second number' /><br><br>");
       out.write("<input type='submit' name='btnsubmit' value='swap' /><br>");
       int a,b;
       a = Integer.parseInt(request.getParameter("txtnum1"));
       b = Integer.parseInt(request.getParameter("txtnum2"));
       out.write("before swap result of a ="+a+" result of b = "+b +"<br>");
       out.write("after swap result of a ="+a+" result of b = "+b +"<br>");
       catch(Exception ex)
           out.print("textfiled can not be null");


Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post