• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet() and doPost() when to use

 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering when to use doGet() and doPost() methods? I hear doGet() is used to get information from the client/browser and doPost() is used to send information back to the broswer? is it true? if so, can someone please give me an example as where to use doGet() and where to use doPost() methods instead of just the definitions?

Thanks.
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You better pick up a book or two on Servlets and JSP. Ideal would be to use Head First JSP and Servlets.

Normally a GET request is just to get anything from a location. POST request is like changing something on a location.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though they both are the means to send the request from client to server, there are differences.

GET Method:

  • GET method appends the name-value pairs on the address bar. Thereby it has got the limitations on the number of characters (hence the values) to be passed.
  • As it is directly making the values visible, certain sensitive information like your credit card number, password etc are not suggested to be sent this way
  • Since the complete values are available in the address bar, it can be easily bookmarked but at times it may be disadvantageous.


  • Post method:
  • It overcomes the aforementioned inconveniences caused by Get method as it sends the values inside the request body.
  • there are no limitations on the number of values to be sent across and no security threats


  • Hope this helps!
     
    Ram Korutla
    Ranch Hand
    Posts: 80
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just to add to Raghavan's, the "GET" action is used generally to retrieve the data from a server machine.
    Although "POST" can accomplish the above the task, it is more often used to post details to a server.. ie updating the database of the server.
    Since the information being posted by a client is generally confidential,the parameters posted from the form are made invisible in the address bar.
     
    Rajkumar balakrishnan
    Ranch Hand
    Posts: 445
    Android Eclipse IDE Windows
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Just to add to Raghavan's, the "GET" action is used generally to retrieve the data from a server machine.

    Is it right?
    And both methods were used to post the values to the server with the difference that Raghavan explained there. So if you need to pass some confidential and huge amount of data then opt for POST method. Otherwise go for GET method. Am i right Raghavan?
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Phani is right but intern he meant to say the idempotent requests.

    It is basically the values you sent to server can be used to just retrieve the values OR to update! In the database (SQL) perspective, it can be told as Select Vs Update! From the client side the values are just sent, but what those values are used for at the server side does matter!

    You may have a look at these threads, RFC for HTTP (Safe and Idempotent) methods and an earlier discussion on the same in Ranch.

    Hope this helps!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic