You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Adrian Beech <a....@bigpond.net.au> on 2004/03/11 15:07:47 UTC
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: Passing init params to a listener?
Posted by Adrian Beech <a....@bigpond.net.au>.
G'day,
I assume from this that init parameters can only be accessed by a listener
if they have been declared globally within the applications context and not
from within the scope of the listener itself?
Hmmmmm....
AB
-----Original Message-----
From: Frank Burns [mailto:frankburns@the-hub.demon.co.uk]
Sent: Monday, 15 March 2004 12:30 AM
To: Tomcat Users List; a.beech@bigpond.net.au
Subject: Re: Passing init params to a listener?
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" <a....@bigpond.net.au>
To: <to...@jakarta.apache.org>
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Passing init params to a listener?
Posted by Frank Burns <fr...@the-hub.demon.co.uk>.
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" <a....@bigpond.net.au>
To: <to...@jakarta.apache.org>
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org