Servlet gets initialized in following two ways 1)Invoke corresponding constructor 2)Call init()
What I want to know is when do container go for these options ie when do container use option 1 and when do container use option 2
~ Pratibha Malhotra<br /> <br />Sun Certified Java Programmer<br />SCEA 1.4 (In Progress)<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />"Many of life's failures are people who did not realize how close they were to success when they gave up!!"
Mat Williams
Ranch Hand
Joined: Jul 20, 2005
Posts: 215
posted
0
Hi,
They both happen as part of the servlets life cycle. The whole life cycle is as follows
1) the servlet is loaded into the jvm 2) constructor is called 3) init(ServletConfig) is called by the container (this calls init() which you can override) 4) container calls service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException for every request it receives for the servlet 5) when the container is about to go down it calls destroy()
Mat
Reghu Ram Thanumalayan
Ranch Hand
Joined: Oct 21, 2003
Posts: 193
posted
0
Originally posted by Rewa Dev: Servlet gets initialized in following two ways 1)Invoke corresponding constructor 2)Call init()
Your question can be rephrased as follows .
The servlet gets constructed in 1 and gets initialized by the container by providing the servlet config in 2. HTH.