You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Donie Kelly <do...@tecnomen.ie> on 2001/12/03 16:46:29 UTC

RE: How to create global variables wich could be accessed by all jsp sites and servlet's?

Have a look at system.properties
eg:
		// Set up new system propeties
            sc = getServletContext();
            RootPath = sc.getRealPath("/");
            			
            propFile = new FileInputStream(RootPath + "myapp.properties");
                        
            Properties p = new Properties(System.getProperties());
            p.load(propFile);
            System.setProperties(p);

Run this in some servlet init() method which "loads on startup" (see
web.xml)

A file like this will then be in your $TOMCAT/webapps/app directory
myapp.properties

# My variable
myvar=myvalue



You can access these variables with 

System.getProperty("myvar")

Hope this helps
Donie

-----Original Message-----
From: Sebastian Hagenbrock [mailto:sebastian.hagenbrock@eventim.de]
Sent: 03 December 2001 14:36
To: Tomcat Maillist
Subject: How to create global variables wich could be accessed by all
jsp sites and servlet's?


Hi,

I've found nothing about how to save Variables wich are stored globally in
reference to one context.

Normally I handle the variables in session objects for each user. But I've
some preferences wich should be read only once at the start of the tomcat
server and then always only read by the classes/jsp sites.

I need it, because the initialisation of these variables consumes much time,
and i have running it now for each new created session object. But it is
only needed once at the servers startup.

How to do that?

Thx

SH

PS: Sorry for my bad english.


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: How to create global variables wich could be accessed by alljsp sites and servlet's?

Posted by Bo Xu <bo...@cybershop.ca>.
> -----Original Message-----
> From: Sebastian Hagenbrock [mailto:sebastian.hagenbrock@eventim.de]
> Sent: 03 December 2001 14:36
> To: Tomcat Maillist
> Subject: How to create global variables wich could be accessed by all
> jsp sites and servlet's?
>
> Hi,
>
> I've found nothing about how to save Variables wich are stored globally in
> reference to one context.
>
> Normally I handle the variables in session objects for each user. But I've
> some preferences wich should be read only once at the start of the tomcat
> server and then always only read by the classes/jsp sites.
>
> I need it, because the initialisation of these variables consumes much
time,
> and i have running it now for each new created session object. But it is
> only needed once at the servers startup.
>
> How to do that?
>
> Thx
>
> SH
>[...]


there are already other ways in other repling-emails, the following is my
suggestions:

if you want to make your Variables visible inside-context,  I think you also
can
save them with:
 - javax.servlet.ServletContext.getAttribute/setAttribute
 - use a class which wrap your variables as a "data container",
   and put this class together with your Servlet class.

if you want to make your Variables visible cross-context,  I think you also
can
save them with:
 - use a class which wrap your variables as a "data container",
   and put this class in JAKARTA_HOME/common/classes or
  JAKARTA_HOME/shared/classes(JAKARTA_HOME/classes)


Bo
Dec.03, 2001



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


AW: How to create global variables wich could be accessed by all jsp sites and servlet's?

Posted by Sebastian Hagenbrock <se...@eventim.de>.
That's it...

Thank you very much.

SH

-----Ursprüngliche Nachricht-----
Von: Donie Kelly [mailto:donie.kelly@tecnomen.ie]
Gesendet: Montag, 3. Dezember 2001 16:46
An: 'Tomcat Users List'
Betreff: RE: How to create global variables wich could be accessed by
all jsp sites and servlet's?


Have a look at system.properties
eg:
		// Set up new system propeties
            sc = getServletContext();
            RootPath = sc.getRealPath("/");

            propFile = new FileInputStream(RootPath + "myapp.properties");

            Properties p = new Properties(System.getProperties());
            p.load(propFile);
            System.setProperties(p);

Run this in some servlet init() method which "loads on startup" (see
web.xml)

A file like this will then be in your $TOMCAT/webapps/app directory
myapp.properties

# My variable
myvar=myvalue



You can access these variables with

System.getProperty("myvar")

Hope this helps
Donie



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>