>> HttpSession.setAttribute( String name, 
>>  Object value)?

no, I want the data available across sessions.

>> The Singleton pattern may be useful if the object
>> will be shared across sessions.

yes, someting like a singleton might work.

>> How about creating a servlet with an init 
>> method and loading it there (should load on app 
>> server startup) and storing it in the application 
>> object...
>> or...
>> Try using lazy loading, and load the data when the 
>> system first needs to access it and then store it 
>> in the application object for future accesses.

ahhh...I think this is what I'm really looking for.  

forgot all about the init() method.  i think i can 
override ActionServlet and provide my own
init() as long as I call super.init() in the 
beginning, right?

Singleton seems like it would work too, though, i was 
really looking for something that might let me access 
the implicit 'application' object from my JSP's.

I was a little confused when reading the docs for 
GenericServlet.init().  They say:

"A convenience method which can be overridden so that 
there's no need to call super.init(config). 

Instead of overriding init(ServletConfig), simply 
override this method and it will be called by 
GenericServlet.init(ServletConfig config).  The 
ServletConfig object can still be retrieved via
getServletConfig()."

I think that stuff doesn't apply because I'm actually 
overriding the init()method in ActionServlet, which 
itself overrides the init() method in GenericServlet.
Correct?

Below is the code I'll attempt to use.  I have one
last question.  How do I let my DAO know about the 
DataSource so it can grab it and get a JDBC
connection?

I guess I could pass it in as an arg, but could I also
use JNDI, or a configuration file?


/**
 * Method to load static data from db during init()
 */
public void init() throws ServletException
{
  // Don't forget this, else no DataSource, etc.
  super.init();

  // Get global application object, 'sc'
  ServletContext sc = 
              getServletConfig().getServletContext();

  // Collect some data from the db
  DataSource ds = findDataSource();
  SomeDataAccessObject dao = 
              new SomeDataAccessObject();

  // How does my singleton service data acess object
  //  know anything about the database/DataSource???
  Collection coll = dao.getCollection( ds );

  // Set an attribute on the global object
  sc.setAttribute( "MY_LIST_OF_OBJECTS", collection );
}


Thank you all!


> -----Original Message-----
> 
> Hi,
> 
> I'd like to load up an global application object
> (say
> reference it from the ServletContext somehow) with a
> collection of data objects I wish to render on my
> JSP.
>  What might be a strategy for doing this?  Do I have
> to use another servlet just to load my global
> object? 
> Ideally I only want the code to run once, and then
> the
> data will be available via regular methods, like
>
[GlobalClassInstance].getCollectionOfPersonObjects()...
>  The data will be pulled from the database with a
> simple SELECT statement.
> 
> Any advice is appreciated...
> 
> 

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to