You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by JB...@silenus.com on 2001/08/14 23:38:26 UTC
Multiple servlets using same initParameters
I have multiple servlets in the same directory and they all get the same
init-params from web.xml.
Currently, I have 5 servlets and am required to repeat all the init-params
5 times, one for each servlet. So if one parameter changes, I have to
change it five times in web.xml. I'd like to only have them in the web.xml
file once and all servlets use them. How is this possible?
One approach I took was to create a servlet that all my other servlets
subclassed and all it did was grab the init-params. I couldn't get it to
work.
Any ideas?
Thanks,
JEB
RE: Multiple servlets using same initParameters
Posted by Martin van den Bemt <ma...@isallineed.org>.
Use a config file or properties file makes life a bit easier.. (at least
that's the way I do it)
Mvgr,
Martin
> -----Original Message-----
> From: Peter Davison [mailto:pdavison@channelwave.com]
> Sent: Tuesday, August 14, 2001 11:51 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Multiple servlets using same initParameters
>
>
> How about this:
>
> Set up your init params for one of your servlets.
> Make sure that this servlet get's pre-loaded first before the other
> servlets.
> Have the init() method of that servlet store all the parameters as
> System properties and let the other servlets retrieve the parameters
> as System properties instead of init params. A bit of a hack but it
> works.
>
> P.
>
>
> On Tue, 14 Aug 2001 17:38:26 -0400
> JBrawner@silenus.com wrote:
>
> > I have multiple servlets in the same directory and they all get the same
> > init-params from web.xml.
> >
> > Currently, I have 5 servlets and am required to repeat all the
> init-params
> > 5 times, one for each servlet. So if one parameter changes, I have to
> > change it five times in web.xml. I'd like to only have them in
> the web.xml
> > file once and all servlets use them. How is this possible?
> >
> > One approach I took was to create a servlet that all my other servlets
> > subclassed and all it did was grab the init-params. I couldn't
> get it to
> > work.
> >
> > Any ideas?
> >
> > Thanks,
> >
> > JEB
>
Re: Multiple servlets using same initParameters
Posted by Peter Davison <pd...@channelwave.com>.
How about this:
Set up your init params for one of your servlets.
Make sure that this servlet get's pre-loaded first before the other
servlets.
Have the init() method of that servlet store all the parameters as
System properties and let the other servlets retrieve the parameters
as System properties instead of init params. A bit of a hack but it
works.
P.
On Tue, 14 Aug 2001 17:38:26 -0400
JBrawner@silenus.com wrote:
> I have multiple servlets in the same directory and they all get the same
> init-params from web.xml.
>
> Currently, I have 5 servlets and am required to repeat all the init-params
> 5 times, one for each servlet. So if one parameter changes, I have to
> change it five times in web.xml. I'd like to only have them in the web.xml
> file once and all servlets use them. How is this possible?
>
> One approach I took was to create a servlet that all my other servlets
> subclassed and all it did was grab the init-params. I couldn't get it to
> work.
>
> Any ideas?
>
> Thanks,
>
> JEB
Re: Multiple servlets using same initParameters
Posted by Jan Labanowski <jk...@osc.edu>.
In web.xml:
<context-param>
<param-name>open-port</param-name>
<param-value>7180</param-value>
<description>Port for regular HTTP via Apache</description>
</context-param>
<context-param>
<param-name>secure-port</param-name>
<param-value>7143</param-value>
<description>Port for HTTPS via Apache</description>
</context-param>
and in the jsp page:
<HTML>
<BODY>
parameters are:<BR>
open-port=<%= application.getInitParameter("open-port") %><BR>
secure-port=<%= application.getInitParameter("secure-port") %><BR>
</BODY>
</HTML>
or in the servlet:
String open_port = getServletContext().getInitParameter("open-port");
String secure_port = getServletContext().getInitParameter("secure-port");
Jan
Jan K. Labanowski | phone: 614-292-9279, FAX: 614-292-7168
Ohio Supercomputer Center | Internet: jkl@osc.edu
1224 Kinnear Rd, | http://www.ccl.net/chemistry.html
Columbus, OH 43212-1163 | http://www.osc.edu/
On Tue, 14 Aug 2001 JBrawner@silenus.com wrote:
> I have multiple servlets in the same directory and they all get the same
> init-params from web.xml.
>
> Currently, I have 5 servlets and am required to repeat all the init-params
> 5 times, one for each servlet. So if one parameter changes, I have to
> change it five times in web.xml. I'd like to only have them in the web.xml
> file once and all servlets use them. How is this possible?
>
> One approach I took was to create a servlet that all my other servlets
> subclassed and all it did was grab the init-params. I couldn't get it to
> work.
>
> Any ideas?
>
> Thanks,
>
> JEB
>
RE: Multiple servlets using same initParameters
Posted by Jim Urban <ji...@netsteps.net>.
This may not work, but is worth a try...
Create a servlet which does nothing other then read the init parameters into
static variables and provides static functions to access the variables
containing the init parameters. Then in web.xml tell this servlet
<load-on-startup>1</load-on-startup> so it will be always be the first
servlet loaded. Then when you need to change a parameter you simply change
it once and restart Tomcat.
Jim Urban
Product Manager
Netsteps Inc.
Suite 505E
1 Pierce Pl.
Itasca, IL 60143
Voice: (630) 250-3045 x2164
Fax: (630) 250-3046
-----Original Message-----
From: JBrawner@silenus.com [mailto:JBrawner@silenus.com]
Sent: Tuesday, August 14, 2001 4:38 PM
To: tomcat-user@jakarta.apache.org
Subject: Multiple servlets using same initParameters
I have multiple servlets in the same directory and they all get the same
init-params from web.xml.
Currently, I have 5 servlets and am required to repeat all the init-params
5 times, one for each servlet. So if one parameter changes, I have to
change it five times in web.xml. I'd like to only have them in the web.xml
file once and all servlets use them. How is this possible?
One approach I took was to create a servlet that all my other servlets
subclassed and all it did was grab the init-params. I couldn't get it to
work.
Any ideas?
Thanks,
JEB