You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by tim <bs...@insightoutsight.com.au> on 2003/08/06 18:21:03 UTC
external parameters to tomcat (how?)
I would like to specify the location of a configuration file to tomcat
which indicates the location of parameters used by some of my servlets.
What is the best practice for doing this? Particularly I want to be
able to get access to the location in any of my servlets.
Thanks
Re: external parameters to tomcat (how?)
Posted by Jon Wingfield <jo...@mkodo.com>.
erm. can't you just use init parameters in the web.xml: section
SRV.2.3.2 in the servlet 2.3 spec.
If the location is for one servlet use a servlet init param otherwise
use a servlet context init param. In the latter case you can access it
in your servlet by doing (for example):
String value = getServletConfig().getServletContext().
getInitParameter(KEY_NAME);
If you need to access an external file you can use an init param as a
path to the file.
Then access it using:
standard java io (if file is outside the container)
ServletContext.getResource(...)
ServletContext.getResourceAsStream(...)
HTH,
Jon
tim wrote:
> I would like to specify the location of a configuration file to tomcat
> which indicates the location of parameters used by some of my servlets.
> What is the best practice for doing this? Particularly I want to be
> able to get access to the location in any of my servlets.
>
> Thanks
>
>
> ---------------------------------------------------------------------
> 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: external parameters to tomcat (how?)
Posted by Jon Wingfield <jo...@mkodo.com>.
erm. can't you just use init parameters in the web.xml: section
SRV.2.3.2 in the servlet 2.3 spec.
If the location is for one servlet use a servlet init param otherwise
use a servlet context init param. In the latter case you can access it
in your servlet by doing (for example):
String value = getServletConfig().getServletContext().
getInitParameter(KEY_NAME);
If you need to access an external file you can use an init param as a
path to the file.
Then access it using:
standard java io (if file is outside the container)
ServletContext.getResource(...)
ServletContext.getResourceAsStream(...)
HTH,
Jon
tim wrote:
> I would like to specify the location of a configuration file to tomcat
> which indicates the location of parameters used by some of my servlets.
> What is the best practice for doing this? Particularly I want to be
> able to get access to the location in any of my servlets.
>
> Thanks
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>