ServletContextListener Example

This tips explains the how to use ServletContextListener. There will be only one ServletContext for each web application. ServletContext will be created while deploying the application. Once the ServletContext is created, it will be used by all the servlets and jsp files in the same application. ServletContext is also called as the application scope variables in the web application scenario.

In the above example ServletContextExample implements ServletContextListener. It has two methods contextInitialized which is called when the ServletContext is created. Another one is contextDestroyed which is called while context is destroyed, this happens normally when web server is shut down or crash.

Comments

comments

Related posts:

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

[…] 12:52 PM as a reply to eric dumond. For instance using a ServletContextListener: take a look at this example. You can then store the file in a static variable, but remember to handle concurrent […]

About Us

Javabeat.net is a blog dedicated to Java/J2EE developers. This site focus on beginners and advanced developers. We constantly write fresh content on J2EE topics like Spring, Hibernate and wide variety of J2EE frameworks.