Miguel,

I assume you have defined a context under your host definition.
Resources can de defined under each context to make it local to that
very same application and that's what I would do if I wanted for
instance to define a parameter and assign a value to so I can retrieve
later on in my application.

Sorry if this is not exactly what you were looking for but perhaps
someone in this forum might be able to shed some light to it.

This is however how I would go about doing it:

Create a context under your host (you probably have done that already).
Under your context create as many parameter resources as you'd like.
Use the following code to retrieve the values assigned to your
parameters in your application:

<%@ page import = "javax.naming.*" %>
String parm = "";
   try
   {
      InitialContext initCtx      = new InitialContext();
      if(initCtx == null) throw new Exception("Boom - No Context");
      Context envCtx              =
(Context)initCtx.lookup("java:comp/env");
//replace any_parameter with the parameter name as defined under your
web.xml file.
              parm                = (String)
envCtx.lookup("any_parameter");
   }
   catch(Exception e) 
   {
      out.println(e.getMessage());
      e.printStackTrace();
   }

It works for me so it should work for you as well unless you have some
specific requirements that don't allow you to use this solution.


Hope this helps.
/JM

-----Original Message-----
From: Miguel Vieira [mailto:[EMAIL PROTECTED] 
Sent: 25 September 2003 16:19
To: [EMAIL PROTECTED]
Subject: RE: Accessing GlobalNamingResources

Thank you for the reply Jo�o.

I've tried the code with no success, all I got was:
javax.naming.NameNotFoundException: Name leaders.archive is not bound 
in this Context
...

My server.xml file has the following GlobalNamingResources:
<Listener 
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" 
debug="0"/>
   <GlobalNamingResources>
     <Environment description="This is a test!" name="leaders.archive" 
override="false" type="java.lang.String" value="LEADERS Archive"/>
     <Environment name="simpleValue" override="true" 
type="java.lang.Integer" value="30"/>
     <Resource auth="Container" description="User database that can be 
updated and saved" name="UserDatabase" scope="Shareable" 
type="org.apache.catalina.UserDatabase"/>
     <ResourceParams name="UserDatabase">
       <parameter>
         <name>factory</name>
         
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
       </parameter>
       <parameter>
         <name>pathname</name>
         <value>conf/tomcat-users.xml</value>
       </parameter>
     </ResourceParams>
   </GlobalNamingResources>

Do I need to create a ResourceLink in the application context in order 
to read a value in the GlobalNamingResources?

Thanks again,
Miguel Vieira

> Miguel,
>
>
>
> I'm assuming you want to access the values as defined for a given
> parameter in your server.xml or in your web.xml files depending on
> whether you want them defined globally or per application.
>
>
>
> Try the folling code in your jsp file and replace the parameter name
> with the appropriate one.
>
>
>
> <<BEGIN CODE SNIPET>>
>
>    String my_var = "";
>
>    try
>
>    {
>
>       InitialContext initCtx      = new InitialContext();
>
>       if(initCtx == null) throw new Exception("Boom - No Context");
>
>       //Context envContext = (Context) initialContext.lookup
> ("java:comp/env");
>
>       Context envCtx              =
> (Context)initCtx.lookup("java:comp/env");
>
>               my_var            = (String)
> envCtx.lookup("my_parameter_name");
>
>    }
>
>    catch(Exception e)
>
>    {
>
>       out.println(e.getMessage());
>
>       e.printStackTrace();
>
>    }
>
> <<END CODE SNIPET>>
>
>
>
> /JM
>
>
>
>> -----Original Message-----
>> From: Miguel Vieira [mailto:[EMAIL PROTECTED]
>> Sent: 25 September 2003 12:35
>> To: [EMAIL PROTECTED]
>> Subject: Accessing GlobalNamingResources
>>
>>
>>
>> Hi,
>>
>>
>>
>> I'm using Tomcat 4.1.19 and I'd like to know if it's possible to 
>> access
>>
>> the GlobalNamingResources, defined in server.xml, from a servlet,
>>
>> without creating a ResourceLink in the servlet's context?
>>
>>
>>
>> Thanks,
>>
>> Miguel Vieira


---------------------------------------------------------------------
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