aspose file tools*
The moose likes Servlets and the fly likes what happens when the first request comes to the webserver? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "what happens when the first request comes to the webserver?" Watch "what happens when the first request comes to the webserver?" New topic
Author

what happens when the first request comes to the webserver?

Pratap gogireddy
Greenhorn

Joined: Dec 03, 2011
Posts: 7
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

Joined: Mar 24, 2008
Posts: 3829

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!


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Pratap gogireddy
Greenhorn

Joined: Dec 03, 2011
Posts: 7
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

Joined: Mar 22, 2000
Posts: 12787
    
    5
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

Joined: Feb 07, 2008
Posts: 6
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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what happens when the first request comes to the webserver?