You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rahul <rj...@yahoo.com> on 2006/03/05 08:46:18 UTC

JSP on Tomcat: application scope variable

Hi, 

I have a simple web application which has two JSP
pages and some class files containing
implementation/logic. These are invoked from the JSP
files. 

I want to store some values e.g. properties from a
properties files in the application scope (or alike)
so that in my class files I can read these values. I
am considering reading these properties in an
implementation of ServletContextListener. 

Where should I store these values and how I can access
them in my class files? 

Thanks,
Rahul.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JSP on Tomcat: application scope variable

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Rahul-
typically the properties file is located on your classpath
Anyone else?
Martin-
----- Original Message ----- 
From: "Rahul" <rj...@yahoo.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Sunday, March 05, 2006 3:42 PM
Subject: RE: JSP on Tomcat: application scope variable


> Thanks. I used a singleton class and initialized it
> from an impl of ServletContextListener.
> 
> If I place a properties file in WEB-INF/classes of my
> webapp, I am unable to read it from my class:
> FileNotFoundException. 
> (Absolute path works fine though.) 
> 
> I have: 
> 
> //properties file in classes
> myProps.load(new FileInputStream("test.properties"));
> 
> or 
> 
> //properties file in classes/com/example/test
> myProps.load(new
> FileInputStream("com/example/test/test.properties"));
> 
> Is this not the correct way to specify the path?
> 
> Thanks,
> Rahul.
> 
> --- Tim Lucia <ti...@yahoo.com> wrote:
> 
>> Since they are in application scope, you can make
>> them part of a Singleton
>> pattern, i.e., make them static values of a class,
>> loaded by the
>> contextInitialized() method.  They could be
>> properties of the listener
>> itself, or to be more properly factored, you can
>> place them in their own
>> class.
>> 
>> Tim
>> 
>> 
>> -----Original Message-----
>> From: Rahul [mailto:rj365@yahoo.com] 
>> Sent: Sunday, March 05, 2006 2:46 AM
>> To: users@tomcat.apache.org
>> Subject: JSP on Tomcat: application scope variable
>> 
>> Hi, 
>> 
>> I have a simple web application which has two JSP
>> pages and some class files containing
>> implementation/logic. These are invoked from the JSP
>> files. 
>> 
>> I want to store some values e.g. properties from a
>> properties files in the application scope (or alike)
>> so that in my class files I can read these values. I
>> am considering reading these properties in an
>> implementation of ServletContextListener. 
>> 
>> Where should I store these values and how I can
>> access
>> them in my class files? 
>> 
>> Thanks,
>> Rahul.
>> 
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around 
>> http://mail.yahoo.com 
>> 
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>> 
>> 
>> 
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>> 
>> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JSP on Tomcat: application scope variable

Posted by Mark Thomas <ma...@apache.org>.
Rahul wrote:
> //properties file in classes/com/example/test
>  myProps.load(new
> FileInputStream("com/example/test/test.properties"));
> 
> Is this not the correct way to specify the path?

Try using getResourceAsStream()

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSP on Tomcat: application scope variable

Posted by Tim Lucia <ti...@yahoo.com>.
Read this:

http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html

It is a how-to on loading properties from the classpath using classloaders.

Tim

-----Original Message-----
From: Rahul [mailto:rj365@yahoo.com] 
Sent: Sunday, March 05, 2006 3:42 PM
To: Tomcat Users List
Subject: RE: JSP on Tomcat: application scope variable

Thanks. I used a singleton class and initialized it
from an impl of ServletContextListener.

If I place a properties file in WEB-INF/classes of my
webapp, I am unable to read it from my class:
FileNotFoundException. 
(Absolute path works fine though.) 

I have: 

//properties file in classes
 myProps.load(new FileInputStream("test.properties"));

 or 

//properties file in classes/com/example/test
 myProps.load(new
FileInputStream("com/example/test/test.properties"));

Is this not the correct way to specify the path?

Thanks,
Rahul.

--- Tim Lucia <ti...@yahoo.com> wrote:

> Since they are in application scope, you can make
> them part of a Singleton
> pattern, i.e., make them static values of a class,
> loaded by the
> contextInitialized() method.  They could be
> properties of the listener
> itself, or to be more properly factored, you can
> place them in their own
> class.
> 
> Tim
> 
> 
> -----Original Message-----
> From: Rahul [mailto:rj365@yahoo.com] 
> Sent: Sunday, March 05, 2006 2:46 AM
> To: users@tomcat.apache.org
> Subject: JSP on Tomcat: application scope variable
> 
> Hi, 
> 
> I have a simple web application which has two JSP
> pages and some class files containing
> implementation/logic. These are invoked from the JSP
> files. 
> 
> I want to store some values e.g. properties from a
> properties files in the application scope (or alike)
> so that in my class files I can read these values. I
> am considering reading these properties in an
> implementation of ServletContextListener. 
> 
> Where should I store these values and how I can
> access
> them in my class files? 
> 
> Thanks,
> Rahul.
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSP on Tomcat: application scope variable

Posted by Rahul <rj...@yahoo.com>.
Thanks. I used a singleton class and initialized it
from an impl of ServletContextListener.

If I place a properties file in WEB-INF/classes of my
webapp, I am unable to read it from my class:
FileNotFoundException. 
(Absolute path works fine though.) 

I have: 

//properties file in classes
 myProps.load(new FileInputStream("test.properties"));

 or 

//properties file in classes/com/example/test
 myProps.load(new
FileInputStream("com/example/test/test.properties"));

Is this not the correct way to specify the path?

Thanks,
Rahul.

--- Tim Lucia <ti...@yahoo.com> wrote:

> Since they are in application scope, you can make
> them part of a Singleton
> pattern, i.e., make them static values of a class,
> loaded by the
> contextInitialized() method.  They could be
> properties of the listener
> itself, or to be more properly factored, you can
> place them in their own
> class.
> 
> Tim
> 
> 
> -----Original Message-----
> From: Rahul [mailto:rj365@yahoo.com] 
> Sent: Sunday, March 05, 2006 2:46 AM
> To: users@tomcat.apache.org
> Subject: JSP on Tomcat: application scope variable
> 
> Hi, 
> 
> I have a simple web application which has two JSP
> pages and some class files containing
> implementation/logic. These are invoked from the JSP
> files. 
> 
> I want to store some values e.g. properties from a
> properties files in the application scope (or alike)
> so that in my class files I can read these values. I
> am considering reading these properties in an
> implementation of ServletContextListener. 
> 
> Where should I store these values and how I can
> access
> them in my class files? 
> 
> Thanks,
> Rahul.
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSP on Tomcat: application scope variable

Posted by Tim Lucia <ti...@yahoo.com>.
Since they are in application scope, you can make them part of a Singleton
pattern, i.e., make them static values of a class, loaded by the
contextInitialized() method.  They could be properties of the listener
itself, or to be more properly factored, you can place them in their own
class.

Tim


-----Original Message-----
From: Rahul [mailto:rj365@yahoo.com] 
Sent: Sunday, March 05, 2006 2:46 AM
To: users@tomcat.apache.org
Subject: JSP on Tomcat: application scope variable

Hi, 

I have a simple web application which has two JSP
pages and some class files containing
implementation/logic. These are invoked from the JSP
files. 

I want to store some values e.g. properties from a
properties files in the application scope (or alike)
so that in my class files I can read these values. I
am considering reading these properties in an
implementation of ServletContextListener. 

Where should I store these values and how I can access
them in my class files? 

Thanks,
Rahul.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org