10.3. Detecting Changes in Servlet Context Attributes

OK, when the Web application is loaded, you can set up initial values of resources and store references to them in the servlet context. But what if you want to be notified whenever these resources change? For example, what if the value of resource B depends on the value of resource A? If resource A changes, you need to automatically update the value of resource B. Handling this situation is the job of servlet context attribute listeners. Using them involves the following steps.

1.
Implement the ServletContextAttributeListener interface. This interface is in the javax.servlet package.
2.
Override attributeAdded, attributeReplaced, and attributeRemoved. The attributeAdded method is triggered ...

Get More Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.