Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use doGet, doPost and service [duplicate]

I was wondering about these servlet methods. i know something about these methods like

  • doPost has no limitations on paramater numbers while doGet has.
  • doGet is faster than doPost.
  • doPost is secured than doGet.

And my question is, as these methods takes same parameters and does the process which we implement. then what is the major difference between these methods and At which specific situation each of this method is used to process.

like image 793
R9J Avatar asked Jul 02 '13 06:07

R9J


2 Answers

doGet():> We will use for static contents, When we will use it, Our request parameters go through http packet header. Or size of http packet header is fixed. So only limited data can be send. or in case of doGet() request parameters are shown in address bar, Or in network data send like plane text.

doPost():>We will use for dynamic contents, When we will use it, Our request parameters go through http packet body. Or size of http packet body is not fixed. So Unlimited data can be send. or in case of doPost() request parameters are not shown in address bar, Or in network data send like encrypted text.

service():> If we will define it then we have to face server connectivity problem because its protocol independent so its not a good approach.

like image 40
SatyamChaudhary Avatar answered Sep 19 '22 13:09

SatyamChaudhary


doGet() and doPost() ,doPut(),doDelete() are called in different occasions with some minor differences.

Yes W3C given some specifications

GET:

A representation of the object is transferred to the client. Some URIs refer to specific variants of an object, and some refer to objects with many variants. In the latter case, the representations, encodings, and languages acceptable may be specified in the header request fields, and may affect the particular value which is returned.

POST

This method of HTTP creates a new object linked to and subordinate to the specified object. The content of the new object is enclosed as the body of the request.

And service() method receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class.

like image 127
Suresh Atta Avatar answered Sep 19 '22 13:09

Suresh Atta