The problem is your servlet init parameters don't exist in the ServletContext.
If you want them to be available to your code, then define them
as init parameters to your application:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>
    <display-name>app name</display-name>

        <context-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
          <description><![CDATA[Struts configuration file]]></description>
       </context-param>
       <context-param>
          <param-name>jcaConnector</param-name>
          <param-value>java:/eis/bongers/autos/content</param-value>
       </context-param>
       <context-param>
          <param-name>tempFile</param-name>
          <param-value>c:/mtbtemp</param-value>
       </context-param>
       <context-param>
          <param-name>properties_db_name</param-name>
          <param-value>bmpauto/bau_content.nsf</param-value>
       </context-param>

etc...


Then your code will yield the expected results.


robert

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 02, 2004 4:45 AM
> To: [EMAIL PROTECTED]
> Subject: ServletContextListener & init parameters
>
>
> Hi all,
>
> I have my ActionServlet serving as a ServletContextListener:
>
> public class ActionServlet
>         extends org.apache.struts.action.ActionServlet implements
> ServletContextListener
>
>
> In the following method (which gets called upon startup) I need the
> ActionServlet init Parameters:
>
> public void contextInitialized(ServletContextEvent event)
>
>
> I want to do something like:
>
> public void contextInitialized(ServletContextEvent event) {
>         ServletContext ctx = event.getServletContext();
>         Enumeration e = ctx.getInitParameterNames();
>         while (e.hasMoreElements()) {
>                 log.debug("Parameter: " + e.nextElement());
>         }
> }
>
> Unfortunatly when I use the code above, my enumeration is empty.
>
> My web.xml looks like this:
>
> <servlet>
>
>         <init-param>
>          <param-name>config</param-name>
>          <param-value>/WEB-INF/struts-config.xml</param-value>
>          <description><![CDATA[Struts configuration file]]></description>
>       </init-param>
>       <init-param>
>          <param-name>jcaConnector</param-name>
>          <param-value>java:/eis/bongers/autos/content</param-value>
>       </init-param>
>       <init-param>
>          <param-name>tempFile</param-name>
>          <param-value>c:/mtbtemp</param-value>
>       </init-param>
>       <init-param>
>          <param-name>properties_db_name</param-name>
>          <param-value>bmpauto/bau_content.nsf</param-value>
>       </init-param>
>
> ... etc ... etc ... etc ...
>
>
> How can I obtain those init parameters when
> contextInitialized(ServletContextEvent event) is called?
>
> Your help is highly appreciated.
>
> Regards,
>
> Harm de Laat
> Informatiefabriek
> The Netherlands.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to