These methods are called by protected service() which is one of life cycle method of servlet. It checks the request´s type. If the type of request is get it calls doGet(). and if request´s type is post then it calls doPost().
Now let´s have a look on internal code:
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
String method = req.getMethod();
long lastModified = getLastModified(req);
if(lastModified == -1L)
//rest of the code
We use it for static contents, When we 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.
We use it for dynamic contents, When we 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.
doPost() shall be used when comparatively large amount of sensitive data has to be sent.
Note: If in a form tag method attribute is set to post, the request will be processed by doPost(), by default it is processed by doGet().