This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Yesterday I attend an interview in one of the MNC.He asked me the following the question.
what happens when the first request comes to the web sever?
I answered like this
when first request comes to the web server it checks in the request header whether it is get method or post method and it can searches the host name and requested resource.if it is found it puts response in the response header and some unique id and sent back to the browser.
The server recognized the requested resource from the URL -
IF the request is to a servlet, AND the servlet has not yet been instantiated, THEN the request Thread waits while the servlet container creates an instance of the servlet and initializes it with a call to init( ServletConfig conf ) You are guaranteed that this will happen before the request proceeds further.
With an initialized servlet instance matching the requested resource in hand, the container constructs request and response objects, then calls the servlet service method.
There are many references for the servlet life cycle which cover this. Here is one example which expands on this.
When a first request comes to the web server...the init method of the servlet is loaded and an instance is created....for the new loaded servlet and then for each request and response internal threads are created and executed..and then followed by the normal servlet life cycle