• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet lifecycle question

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when is servlet context created? and when is it destoryed? is init() called before or after servlet context created?
 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ron Miller
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you explain it well. thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic