| Deletions are marked like this. | Additions are marked like this. |
| Line 23: | Line 23: |
|
---- See also * http://e-docs.bea.com/wls/docs81/webapp/app_events.html#175768 |
Since J2EE Servlet v2.3, there's an easy, standard way to hook in your initialization at deployment time. You simply write a [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html ServletContextListener] and reference it in your web.xml with
<listener>
<listener-class>
com.idiacomputing.startup.StartupServletContextListener
</listener-class>
</listener>ServletContextListener defines two method signatures, contextInitialized and contextDestroyed. Both are passed a [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextEvent.html ServletContextEvent] containing the ServletContext of your webApp.
The [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html ServletContext] contains such goodies as the context-param elements of the web.xml file
private void extractServletContextParameters(Map nameValuePairs, ServletContext servletContext) {
Enumeration parmEnum = servletContext.getInitParameterNames();
while (parmEnum.hasMoreElements()) {
String name = (String) parmEnum.nextElement();
String value = servletContext.getInitParameter(name);
nameValuePairs.put(name, value);
}
}See also
