wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet Initialization" Watch "Servlet Initialization" New topic
Author

Servlet Initialization

Pratibha Malhotra
Ranch Hand

Joined: Dec 21, 2003
Posts: 199
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
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
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.


Cheers,<br />Reghu Ram T<br /> <br />SCJP 1.4 - 98 %, SCBCD 1.3 - 94 %, SCMAD 1.0 - 92 %
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Initialization
 
Similar Threads
frnds come up with solution
MVC Architecture
Reloading
MVC Architecture.
when does a servlet clas get servletness ?