top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between doGet() and doPost() ?

+2 votes
513 views
What is the difference between doGet() and doPost() ?
posted Feb 4, 2015 by Shyam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

There are 7 http methods but almost in 99% of web application you will be dealing with either

               a doGet() or a doPost() method.

If user request is a get request than doGet() method of servlet is called and if the request via a post than doPost() method is called and all the business logic goes into either a doGet() or a doPost() method of servlet.

doGET: The GET method appends the name-value pairs on the request’s URL. Thus, there is a limit on the number of characters and subsequently on the number of values that can be used in a client’s request. Furthermore, the values of the request are made visible and thus, sensitive information must not be passed in that way.

    public void doGet(HttpServletRequest request,  HttpServletResponse response)
    throws ServletException, IOException {
    // Servlet code
   }

doPOST: The POST method overcomes the limit imposed by the GET request, by sending the values of the request inside its body. Also, there is no limitations on the number of values to be sent across. Finally, the sensitive information passed through a POST request is not visible to an external client.

       public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
         // Servlet code
      }
answer Feb 6, 2015 by Karthick.c
...