Skip to main content

Get and Post method of Servlet

What determine whether browser send get or post Request ?
  • Typing a URL in browser make request to contain get method.
  • Clicking on hyperlink in browser makes request to contain get method.
  • Submitting the form with method=”get” in browser makes request to contain get method.
  • Submitting the form with method=”post” in browser makes request to contain post method.
  • Submitting the form with “No method” form attribute declaration in browser makes request to contain get method.

Note:

  • Depending on the HTTP method present in the request, Corresponding doXXX() method get executed at server side.
  • Hence whenever servlet gets a request via submitting form then we have to override doPost() method and rest of case we have to override doGet() method.
Get method
  • Get is meant for getting the data from server.
  • It is default method.
  • Get do not have body or have empty body.
  • Hence data sent using get will be present in header part of request in form of query string.
  • It is less Secure because form data get expose to the outside world.
  • Amount of data you can send using get is restricted because URL can only contain 1024 character.
  • We can not send file using get method.
  • Get request are inherently idempotent in nature that is we can perform same operation again and again without any side effect.
  • We can bookmark the get request but you can not bookmark the post request.
Post method
  • Post is meant for Posting the data into server.
  • It is not  default method we have to explicitly define get=”post” in HTML form.
  • Post request  do  have body  body.
  • Hence data sent using Post will be present in Body part of request.
  • It is Secure because form data present in body part of request.
  • Amount of data you can send using Post is not restricted so you can send data of unlimited size.
  • We can send file using Post method.
  • Post request non idempotent in nature so you can not perform same operation again and again without any side effect.
  •  you can not bookmark the post request.