• 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

how can we make and use servlet context listener???

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can we make and use servlet context listener???
who will listen.???
i know that we made servlet context for webapplication
for passing parameter
please help me to understand this
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method names in the API pretty much sum it up.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContextListener.html

You have two methods:
contextInitialized gets called before any servlets get loaded. This is a good place to put any application initialization code.

and:
contextDestroyed. This gets called after all the servlets have been destroyed but before your context is destroyed.
This is a good place to put any cleanup code.


Before context listeners, the only way to run initialization code for the app was to put it in a servlet and trigger it with the load-on-startup attribute in web.xml. This really didn't follow the spirit of what a servlet should do (listen for requests and issue a response). You also had to keep track of what servlets were there only to initialize the app and make sure that they had a load-on-startup value that was lower than any servlet which might need to have that initialization done in order to work.
reply
    Bookmark Topic Watch Topic
  • New Topic