For each parameter you need your listener to read, place name/value pairs in
your web.xml. Here's an example for two parameters (mySQLServerName and
mySQLPort):

 <context-param>
  <param-name>
   mySQLServerName
  </param-name>
  <param-value>
   localhost
  </param-value>
 </context-param>

 <context-param>
  <param-name>
   mySQLPort
  </param-name>
  <param-value>
   3306
  </param-value>
 </context-param>

Then, in your listener class, read them like this:

String serverName = application.getInitParameter("mySQLServerName");
String mySQLPort = application.getInitParameter("mySQLPort");


----- Original Message ----- 
From: "Adrian Beech" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 11, 2004 2:07 PM
Subject: Passing init params to a listener?


G'day all,

Can someone please advise how to pass init params to a listener?  For
example, in my web.xml file I have the following listener currently defined
as:-

  <listener>
    <listener-class>czone.db.InitConnectionPool</listener-class>
  </listener>

At the moment all parameters are hard coded in the listener.  If I want to
extend the flexibility of the code by adding init parameters to the listener
definition do I merely do this:-

  <listener>
    <listener-class>czone.db.InitConnectionPool</listener-class>

    <init-param>
      <param-name>jdbcConnectionString</param-name>
      <param-value>...</param-value>
    </init-param>
  </listener>

If this is correct then what Java code is required in the
contextInitialized(...) method to pull the init parameter name and value so
the listener can use it?

I really don't have a clue what I'm doing so some guideance on this matter
would be greatly appreciated!

Thanks if you can help.

AB



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


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

Reply via email to