It is simply used to get the notifications of the context events. Like,when you want to perform some specific task when context is destroying then you will have to implement this ServletContextListener...
Originally posted by sandeep Talari: give explaination somebody plzzzzzzz
sandeep, Welcome to JavaRanch!
In an effort to help you get the most from our forums, we've compiled a list of tips for asking questions here. You can find the list in our FAQ section here. In particular please see: UseRealWords
Abbreviations such as "u" or "ur" in place of "you" and "you are" or "you're" confound language translation software making it hard for our non-English speaking members to read your posts. "plzzzz" is not a word in the English language.
Again, welcome to JavaRanch and good luck with your question. -Ben
A context listener give you a reliable place to put code that you want executed when a context starts up and shuts down.
Prior to contextListners, the only place where you could put startup and shutdown code was in the init or destroy method of a servlet. This was less than optimal because, first and foremost, servlets were not meant to serve this purpose. They were meant to respond to requests. Secondly, when init code is put in a servlet, it is up to the developers and administrators to make sure that no other servlets, that rely on that startup code, are initialized before that servlet. The load-on-startup attribute is configurable in web.xml so it's possible that an administrator who doesn't know about the init code could alter the order. Thirdly, the spec allows containers to load an unload servlets at any point in the application to conserve resources. If this happens to the servlet containing the init and destroy code, it could cause problems with the application.
Context listener's contextInitialized methods, on the other hand, are guaranteed to be run before any servlets are loaded. Likewise the contextDestroyed method is run only after all of the servlets have been unloaded. It also guaranteed that each of these methods will only be run once in an application's lifecyle. Most importantly, using context listeners allows servlets to do what they were intended to do and nothing else; response to requests.