Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on servletcontextlistener within the Java forums, part of the Software Development category; wats the purpose of servletcontextlistener class...
|
|||||||
|
|||
|
Re: servletcontextlistener
Hi joy,
servletcontextlistener class handles notifications about changes to the servlet context of the web application that they are part of. This can be explained as if someone is present on the server and dynamically informing us about the events that are occuring on the server. There acquire need of listners. Therefore, servletcontextlistner is helpful in informing about context initilazation and destruction. Eg: import javax.servlet.servletcontextlistener; import javax.servlet.servletcontextevent; import javax.servlet.*; public class mylistener implements servletcontextlistener { { private servletcontext context = null; /*this method is invoked when the web application has been removed and is no longer able to accept requests */ and............... Public void contextdestroyed(servletcontextevent event) { //output a simple message to the server's console system.out.println("the simple web app. Has been removed"); this.context = null; } //this method is invoked when the web application is ready to service requests. Public void contextinitialized(servletcontextevent event) { this.context = event.getservletcontext(); //output a simple message to the server's console system.out.println("the simple web app. Is ready"); } } <web-app> <listener> <listener-class> com.listeners.mycontextlistener </listener-class> </listener> <servlet/> <servlet-mapping/> </web-app> Thanks... Riju. Last edited by rijus; 06-04-2009 at 07:07 AM. |
| The Following User Says Thank You to rijus For This Useful Post: | ||
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|