• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when ServletConfig object is created?

 
Mukil Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In HFS&J, first they said servletconfig object is created for a servlet at the time of deployment. It reads servlet's init param defined in DD while deploy the application.

But I read earlier in the book, servlet is loaded and initialized when a servlet gets first request, container initializes it?

So, exactly when the servlet config object is created?

Any one can explain me??

Thanks,
Sumathi
 
S.L.Narayanan
Ranch Hand
Posts: 431
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before handling any requests two things have to be done by the Container,

1. Instatntiating the Servlet Object (Done only once in a JVM).

2. Initializing the Servlet - This has to be done before calling the Service method.

So the ServletConfig which is specific to each servlet is created when the servlet is being initialized. Usually the Container calls the



where it needs to specify the ServletConfig object. Even if you override the init method you usually override the no-arg init (init())only. This function will be called from init(ServletConfig).

So the container creates the ServletConfig object and adds the ServletConfig init-parameters specfied in the DD before initializing the servlet.
 
Conan King
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sumathi,

Consider the following stages in the lifecycle of a servlet

1. Servlet class gets loaded into JVM on first request. This consists of loading Servlet class and calling the compiler supplied no argument constructor.

2. Container creates servletconfig object.

3. Then the init method is called and the servletconfig object is passed as argument to the init method.

4. Now onwards whenever a new request comes, a thread for the servlet is generated and service method for the servlet handles the request.

5. When the servlet is destroyed (by bringing down the server) the destroy() method is called.

Steps 1, 2, 3 take place only during the first request to the servlet, and 4 multiple times on each request

Now the reason you are possibly confused is because you read the statement that the servletconfig object is created only when the servlet is redeployed. This is true because the first 3 steps are not called on each request and and change in configuration parameters would need redeployment of servlet.

Hope this helps.
 
Kumar J
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u plz mention the page no. on which this statements are made?
 
Mukil Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm clear now.
Thnaks for your clarifications.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic