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

Solution:

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

The code below shows the BasicServlet class which has doGet and doPost methods to be implemented.

Get and Post methods

public class BasicServlet extends HttpServlet 
{
  
   public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
      {
     
      }
     
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException
      {
     
      }    
     
}
0 answers