3. The Servlet Container Model
3.1. Servlet Context Init Parameters
3.1.1.1. purpose: defines init parameters accessible
by all servlets in the web application context; set-able
at deployment-time, but accessible at run-time
3.1.1.2.
interfaces (or classes): javax.servlet.ServletContext
3.1.1.3. methods: public Enumeration getInitParameterNames()
and public String getInitParameter(String name)
3.1.1.4.
webapp deployment descriptor element name: <context-param>
{param-name, param-value} </context-param>
3.1.1.5.
behavior in a distributable: Consider that a different instance
of the ServletContext may exist on each different JVM and/or
machine. Therefore, the context should not be used to store
application state. Any state should be stored externally,
e.g. in a database or ejb.
3.2. Servlet Context Listener
3.2.1.1. purpose: An object that implements the ServletContextListener
interface is notified when its web app context is created
or destroyed
3.2.1.2. interfaces (or classes): javax.servlet.ServletContextListener
3.2.1.3. methods:
3.2.1.3.1. void contextInitialized(ServletContextEvent
e): called during web server startup or when context is
added or reloaded; requests will not be handled until this
method returns
3.2.1.3.2. void contextDestroyed(ServletContextEvent
e): called during web server shutdown or when context is
removed or reloaded; request handling will be stopped before
this method is called
3.2.1.4. webapp deployment descriptor
element name: <listener> <listener-class> {fully
qualified class name} </listener-class> <listener>
3.2.1.5. behavior in a distributable: Each context instance
(on different jvm's and/or machines) will have its own instance
of the listener object. Therefore, if a context on one jvm/machine
is initialized or destroyed, it will not trigger a listener
on any other jvm/machine.