• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what happens when the first request comes to the webserver?

 
Pratap gogireddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends


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.

is this answer is right or wrong?

can anyone please explain me clearly?

Thanks in advance....
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens when the first request comes to the web sever?

First request to what, for a given servlet? What you are trying to explain is the general case for every request.

And welcome to the CodeRanch!
 
Pratap gogireddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI vijith

I am saying when the first request comes to webserver.for example i am a user hits the web server(for first time) for a particular resource what happens internally?

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill


 
nirmal singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirmal singh wrote:When a first request comes to the web server...the init method of the servlet is loaded and an instance is created....

Not necessarily. You can setup your web container to create and init servlets when the container starts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic