• 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

ServletContextListener method calls

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) contextInitialized()called after the ServletContext is created.Am I correct?

2) contextDestroyed() called before the ServletContext becomes eligible for GC.Am I correct?

I guess it has to be that way else it will be analogous to this:
DOCTOR TO PATIENT--Take one pill in the night after sleeping and other before getting up in the morning.Or am I totally wrong and missing an entire scheme of the almighty container??

3)On page 164 para 4 of HFS&J authors mention "You can't really put that code inside..." but I conjured up an ugly way of doing that.See the snippet


......
String dburl=getServletContext().getInitParameter("DBConnectionURL");
Connection tomydb=getServletContext().getAttribute("DBCONN");
if(tomydb==null)
{
//code to make db conn and place it in the context
}
else
{
some other servlet already did that so just use it
}
......

I can place this code in init() of ALL my app's servlets who use DB and I am done.

PROS:Better if your company pays you by number of lines of code )
CONS:repetitive code in multiple servlets and if you forget to cut-paste-copy this even in one of the servlets using DB and by ur sheer misfortune it runs before others u r doomed
 
reply
    Bookmark Topic Watch Topic
  • New Topic