Andrew Dickson wrote:
> Hello,
>
> I am working on programming a web front end for a database using
> servlets. My problem is that I would like to have some java objects that
>
> load the data so that it can be accessed quickly by servlet calls,
> rather than having to read and parse the data files each time. However,
> I can't think of a way to have the servlet objects get access to the
> data objects that are loaded. Is there a way to somehow register the
> objects with the system? Any suggestions or thoughts on ways to approach
>
> this problem would be much appreciated.
>
> Thanks,
> Andrew Dickson
>
If the objects you load should be shared among the various servlets (and/or
JSP pages) of a particular application, use the ServletContext.setAttribute()
method to store them in the servlet context for your application, and
ServletContext.getAttribute() to retrieve them. This is kind of like the
Singleton design pattern, but is restricted to your particular application.
If the objects you want are specific to a particular user's usage of the
application, you can store them in the user's session instead.
>From the point of view of performance, ServletContext.getAttribute() and
HttpSession.getValue() are pretty much as fast as a Hashtable lookup, because
that is usually how they are implemented under the covers.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html