When init() method is called?
(a) init method will be executed immediately after loading and instantiation of the servlet class takes place.
(b) Container differs the initialization till the first client asks for service.
Servlet Specification doesn't state exactly when init method should be called. But it will be called surely before servlet can serve to its first request.
From Servlet Spec
After the servlet object is instantiated, the container must initialize the servlet before it can handle requests from clients.
Instantiation ==> Calling the no-arg’s constructor of the servlet class.
Initialization ==> Calling the init() method.
Hence it is wiser to answer as init() method will be execute when the servlet class is loaded by the container.
0 Comments:
Post a Comment
<< Home