Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: servlets - application level object

Reply
Thread Tools

Re: servlets - application level object

 
 
John C. Bollinger
Guest
Posts: n/a
 
      07-02-2003
Miguel De Anda wrote:
> Is there some application level object that I can use to store settings such
> as database connection info and directory settings? I need something that is
> at least readable throughout my servlets (writing settings after initialized
> is not important).


In addition to the other suggestions, you can also store objects as
attributes of the ServletContext, from which any servlet can later
retrieve them. (This can in fact be combined with the
ServletContextListener approach, because the ServletContextListener can
add attributes to its associated ServletContext -- even itself.)


John Bollinger
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Miguel De Anda
Guest
Posts: n/a
 
      07-02-2003

"John C. Bollinger" <(E-Mail Removed)> wrote in message
news:bduqjn$v6s$(E-Mail Removed)...
> Miguel De Anda wrote:
> > Is there some application level object that I can use to store settings

such
> > as database connection info and directory settings? I need something

that is
> > at least readable throughout my servlets (writing settings after

initialized
> > is not important).

>
> In addition to the other suggestions, you can also store objects as
> attributes of the ServletContext, from which any servlet can later
> retrieve them. (This can in fact be combined with the
> ServletContextListener approach, because the ServletContextListener can
> add attributes to its associated ServletContext -- even itself.)
>
>
> John Bollinger
> (E-Mail Removed)
>


Would the ServletContext method (not getResourceAsStream) be considered more
'standard'? We've just moved to jsp and want to do things the way they are
normally done. It seems like using getResourceAsStream would have to be
called anytime I need to read properties right? That seems inefficient,
especially since these are properties that will be needed for more pages.


 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      07-02-2003
Miguel De Anda wrote:
> "John C. Bollinger" <(E-Mail Removed)> wrote in message
> news:bduqjn$v6s$(E-Mail Removed)...
>
>>Miguel De Anda wrote:
>>
>>>Is there some application level object that I can use to store settings

>
> such
>
>>>as database connection info and directory settings? I need something

>
> that is
>
>>>at least readable throughout my servlets (writing settings after

>
> initialized
>
>>>is not important).

>>
>>In addition to the other suggestions, you can also store objects as
>>attributes of the ServletContext, from which any servlet can later
>>retrieve them. (This can in fact be combined with the
>>ServletContextListener approach, because the ServletContextListener can
>>add attributes to its associated ServletContext -- even itself.)
>>
>>
>>John Bollinger
>>(E-Mail Removed)

>
> Would the ServletContext method (not getResourceAsStream) be considered more
> 'standard'? We've just moved to jsp and want to do things the way they are
> normally done. It seems like using getResourceAsStream would have to be
> called anytime I need to read properties right? That seems inefficient,
> especially since these are properties that will be needed for more pages.


For objects that need to persist and especially those that have state
that may change, storing references as ServletContext attributes is the
standard means provided by the servlet API. Such attributes might be
populated from a stream obtained via ServletContext.getResourceAsStream
if they are static and many or large, but might be better off as context
parameters (defined in web.xml) if they are static, few, and small.
Dynamic objects, such as database connections, must of course be created
at runtime, but the parameters for their creation might come from
context parameters. Once you have that DB connection you can of course
use the DB for persistent storage (of most things) if you so choose.

John Bollinger
(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java servlets: Hi All! I want to display xml file in browser using servlets datta.saru Software 0 05-15-2006 03:30 PM
c is a low-level language or neither low level nor high level language pabbu C Programming 8 11-07-2005 03:05 PM
Is Cisco PIX Application level firewall or Packet level firewall? Learning Cisco Cisco 3 10-15-2005 12:55 AM
Re: servlets - application level object Phil Hanna Java 0 07-02-2003 02:37 AM
Re: servlets - application level object Wendy S Java 0 07-01-2003 01:07 AM



Advertisments