What will happen inside init() in servlet. my interviewer
asked servlet lifecycle. i said "once servlet is loaded in
to memory init() will be called which performs servlet
initialization " . Again interview asked what values will be
initialized . what is difference between init() and
init(ServletConfig config).

Answer Posted / amit singh

when the first request goes to the container then first
container create the object and the constructor execute
then init() method called
note: thatGenericServlet has an
init(ServletConfig conf ) method require by the Servlet
interface. If you don't override init(ServletConfig conf),
then the GenericServlet method will be called - it in turn
calls the init() method.
so if you use the override the init(ServletConfig con)
so you should to call the super.init(ServletConfig con)
which in turn call the lnlt()
2)what will happen inside the init() its use to intialize
teh parametr which you give in a web.xml
so it intialize the custom parmeter and other paranetr too
so its just for intialization
because wedon't do intialization through constructor
bracuse the object of servlet will create by webcontainer
and execution of constructor too so we use thr init method
for initializtion because we are not able to use new for
creating a object in sevlet
thanks amit singh

amitsing2008@gmail.com

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does regex mean?

574


How many types of equations are there?

550


What is a line separator in java?

543


What do you mean by ordered and sorted in collections in java?

558


How to display all the prime numbers between 1 and 100

512






What is array and arraylist in java?

537


Which is a valid identifier?

558


What is the difference between the paint() and repaint() methods in java programming?

641


What is square root in java?

594


What are the two parts of a conditional statement?

522


Why enumeration is faster than iterator?

533


What is the difference between Java1.4 and Java1.5

1836


What are memory tables?

612


What is the purpose of the return statement?

522


What is bool mean?

575