You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by neal <ne...@yahoo.com> on 2002/09/16 07:42:03 UTC

Accessing environmental variables

How does one access these environmental variables being assigned from the
web.xml file?

I have tried accessing the servletContext presuming it would be available
there but no luck - its coming back null.  :(

     ServletContext application = getServletContext();
     String owner = (String)application.getAttribute("owner");

And here's my variable definition from the web.xml file:

    <!-- Environmental Variables Definitions -->
    <env-entry>
      <env-entry-name>owner</env-entry-name>
      <env-entry-value>Neal</env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <!-- /Environmental Variables Definitions -->


Thanks.
Neal



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Accessing environmental variables

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
neal wrote:
> I guess I don't understand.  Are you suggesting that I should be able to
> access a parameter rather than an attribute?  The closest thing I could find
> in the API is getInitParameter() but this is of course for passing initial
> values in for a specified servlet.  Any chance you could reword your
> suggestion?  I appreciate it.  :)

The element you're looking for is <context-param>.

<context-param>
   <description>A parameter in web app context</description>
   <param-name>test</param-name>
   <param-value>My test</param-value>
</context-param>

You'll retrieve it via getAttribute( "test" ) of your application context. The 
value type is "String".

Nix.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Accessing environmental variables

Posted by Miguel Angel Mulero Martinez <mi...@mad.tecsidel.es>.
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-resources-howto.html


-----Mensaje original-----
De: neal [mailto:nealcabage@yahoo.com]
Enviado el: lunes, 16 de septiembre de 2002 8:36
Para: Tomcat Users List
Asunto: RE: Accessing environmental variables

I guess I don't understand.  Are you suggesting that I should be able to
access a parameter rather than an attribute?  The closest thing I could find
in the API is getInitParameter() but this is of course for passing initial
values in for a specified servlet.  Any chance you could reword your
suggestion?  I appreciate it.  :)

Neal


-----Original Message-----
From: Nikola Milutinovic [mailto:Nikola.Milutinovic@ev.co.yu]
Sent: Sunday, September 15, 2002 11:05 PM
To: Tomcat Users List
Subject: Re: Accessing environmental variables


neal wrote:
> How does one access these environmental variables being assigned from the
> web.xml file?
>
> I have tried accessing the servletContext presuming it would be available
> there but no luck - its coming back null.  :(
>
>      ServletContext application = getServletContext();
>      String owner = (String)application.getAttribute("owner");

With that API you can access <parameter> (if I remember the name correctly)
elements of the application context.

> And here's my variable definition from the web.xml file:
>
>     <!-- Environmental Variables Definitions -->
>     <env-entry>
>       <env-entry-name>owner</env-entry-name>
>       <env-entry-value>Neal</env-entry-value>
>       <env-entry-type>java.lang.String</env-entry-type>
>     </env-entry>
>     <!-- /Environmental Variables Definitions -->

This smells like JNDI, but I'm not sure.

Nix.


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Accessing environmental variables

Posted by neal <ne...@yahoo.com>.
I guess I don't understand.  Are you suggesting that I should be able to
access a parameter rather than an attribute?  The closest thing I could find
in the API is getInitParameter() but this is of course for passing initial
values in for a specified servlet.  Any chance you could reword your
suggestion?  I appreciate it.  :)

Neal


-----Original Message-----
From: Nikola Milutinovic [mailto:Nikola.Milutinovic@ev.co.yu]
Sent: Sunday, September 15, 2002 11:05 PM
To: Tomcat Users List
Subject: Re: Accessing environmental variables


neal wrote:
> How does one access these environmental variables being assigned from the
> web.xml file?
>
> I have tried accessing the servletContext presuming it would be available
> there but no luck - its coming back null.  :(
>
>      ServletContext application = getServletContext();
>      String owner = (String)application.getAttribute("owner");

With that API you can access <parameter> (if I remember the name correctly)
elements of the application context.

> And here's my variable definition from the web.xml file:
>
>     <!-- Environmental Variables Definitions -->
>     <env-entry>
>       <env-entry-name>owner</env-entry-name>
>       <env-entry-value>Neal</env-entry-value>
>       <env-entry-type>java.lang.String</env-entry-type>
>     </env-entry>
>     <!-- /Environmental Variables Definitions -->

This smells like JNDI, but I'm not sure.

Nix.


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Accessing environmental variables

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
neal wrote:
> How does one access these environmental variables being assigned from the
> web.xml file?
> 
> I have tried accessing the servletContext presuming it would be available
> there but no luck - its coming back null.  :(
> 
>      ServletContext application = getServletContext();
>      String owner = (String)application.getAttribute("owner");

With that API you can access <parameter> (if I remember the name correctly) 
elements of the application context.

> And here's my variable definition from the web.xml file:
> 
>     <!-- Environmental Variables Definitions -->
>     <env-entry>
>       <env-entry-name>owner</env-entry-name>
>       <env-entry-value>Neal</env-entry-value>
>       <env-entry-type>java.lang.String</env-entry-type>
>     </env-entry>
>     <!-- /Environmental Variables Definitions -->

This smells like JNDI, but I'm not sure.

Nix.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>