File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servlet lifecycle question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servlet lifecycle question" Watch "servlet lifecycle question" New topic
Author

servlet lifecycle question

Ron Miller
Greenhorn

Joined: Jun 28, 2010
Posts: 12
when is servlet context created? and when is it destoryed? is init() called before or after servlet context created?
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 308

Ron Miller wrote:when is servlet context created? and when is it destoryed? is init() called before or after servlet context created?

Hi Ron,

The ServletContext is available for all servlets / jsp's in your web application. So it is created before the init() method in Servlet is called. It's life time is pretty much the life time of the web application. ServletConfig is also created before init() method and passed in as a parameter to init(ServletConfig config) method.

You can create a class implements ServletContextListener and override contextInitialized(), contextDestroyed() methods. Add
in web.xml. See for yourself when is context initialized and destroyed.


SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
Ron Miller
Greenhorn

Joined: Jun 28, 2010
Posts: 12
you explain it well. thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet lifecycle question