• Post Reply Bookmark Topic Watch Topic
  • New Topic

confused about difference between doGet/doPost methods and request/response variables  RSS feed

 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, we have request and response local variable parameters in doGet and doPost method like this -

doGet -


doPost -



doPost method is used- when we want to write the data to the server
doGet method is used - when we want to fetch the data from the server
The what  request and response variables do.
i guess request - fetches the data from the page
and response - writes the data back to the page
.
here request variable does the same job as doGet method and doPost does the same job as response. then y are the local variables used. I have confusion amongst their working.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sucheta Shrivastava wrote:doPost method is used- when we want to write the data to the server

Sort of, but that's not complete. Essentially a POST is used when an operation is to be performed -- to include writing data.
doGet method is used - when we want to fetch the data from the server

Pretty much.

An important point to note is that GETs must be idempotent: that is, the same GET made again and again returns the same value. POSTs do not have this restriction.

The [sic] what  request and response variables do.

The request instance represents the HTTP request made to the server from the client. It contains all the information for the request: parameters, method, headers, and so on.

and response - writes the data back to the page

The response instance represents the HTTP response that will be sent to the client from the server. Note I didn't use the word "page". The client can be anything, not just a browser.

here request variable does the same job as doGet method and doPost does the same job as response.

No. The request and response are the same for all methods, including GET and POST. See above.

then y are the local variables used. I have confusion amongst their working.

Please use real words when posting. "why" not "y". Thanks.

Local variables defined within the methods are there for the method to use internally to do whatever it needs to do, just as with any other Java class methods. They have no bearing outside the method and are discarded when the method exits.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!