• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
harish goyal
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!