| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| 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 | 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 |
| Line 10: | Line 10: |
| S''''''ervletContextListener 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 S''''''ervletContext of your webApp. | S''''''ervletContextListener 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 S''''''ervletContext of your webApp. |
| Line 12: | Line 12: |
| 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 | 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 |
Since J2EE Servlet v2.3, there's an easy, standard way to hook in your initialization at deployment time. You simply write a 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 ServletContextEvent containing the ServletContext of your webApp.
The 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
