Hi guys.. Well can u tell me that why there is need of
"init()" , i mean why can not we initialize the servlet object
with the help of constructors?
Thank you.

Answers were Sorted based on User's Feedback



Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / neha rajpal

the very first step of creating the servlet is making its
object after until and unless you will not trigger the init
method it will be treated as simple object not the servlet
after triggering the init method it get the servlet config
init parameters and then only it is called as servlet so its
very imp to intiate the init method

Is This Answer Correct ?    2 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / abhijit mishra

As per Servlet specification, the servlet container is
responsible for creating the servlet and initializing it( or
making it ready for client to request it).

So according to the Client:servlet container contract, the
servlet creation and inialization is done by the container
which will differ for different container provider.

So u can't use constructors to create servlets.

Is This Answer Correct ?    2 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / manas banerjee

you can use but should not.the original reason for init()
was that ancient version of java could not dynamically
invoke constructors with arguments.so there was no way to
give the constructors a ServletConfig.So u would not have
to access to ServletConfig or ServletContext.

{{in short:init() has access to servletconfig and
servletcontext object constructor would not..

Is This Answer Correct ?    1 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / archana

When u create a servlet with a constructor it wont be a
complete servlet but will be in a akward state where it
cannot access Servlet Context and Config.It has to go
through the init() method (though we dont know what code is
written there) to be a complete servlet

Is This Answer Correct ?    1 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / karnbakar

as a programmer u cant create object for servlet ,container
invokes default constructor of the servlet

Is This Answer Correct ?    1 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / gaurav agrawal

If we initialize the servlet via constructor then we cant
access the ServletConfig object at the time of
initialization.

Is This Answer Correct ?    0 Yes 0 No

Hi guys.. Well can u tell me that why there is need of "init()" , i mean why can not we i..

Answer / ravikiran.chd

no the servlet config object is only available at the time
init() method call

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Servlets Interview Questions

Can we override servlet service method?

0 Answers  


What is the functionality of actionservlet and requestprocessor?

0 Answers  


What is URL Rewriting ?

2 Answers  


How session tracking can be achieved, if your browser doesn't support cookies (or) if cookies are disabled?

2 Answers  


How does Cookies work in Servlets?

0 Answers  






Explain the different ways for servlet authentication?

0 Answers  


What is the advantage of Servlets when compared with other server side technologies?

0 Answers  


What are the features added in Servlet 2.5?

0 Answers  


how to link html file to sevlet file.one name is textbox,c&c++ is cheakbox,bc&mca is radio button and one submit buttonis ok why in this programme use in servelt file

0 Answers  


Which is better approach among four(HttpSession,cookie,URL Rewriting, Hidden Fields) Session Tracking technic's ? Why ?

3 Answers   L&T,


Who is responsible to create the object of servlet?

0 Answers  


What is webservlet?

0 Answers  


Categories