Forums Register Login

when ServletConfig object is created?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Can u plz mention the page no. on which this statements are made?
+Pie Number of slices to send: Send
I'm clear now.
Thnaks for your clarifications.
We begin by testing your absorbancy by exposing you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4366 times.
Similar Threads
ServletConfig : is it created one for each servlet?
servletconfig object
Regarding the init() methods
why init() method is not final?
ServletConfig redundant?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:26:42.