Willie Wheeler wrote:

> Hi all,
>
>         In a JSP, is it appropriate to use the implicit 'application'
> ServletContext as a repository for application-level objects that I want
> to create?  E.g., let's say I want to create 200 MultipleChoiceQuestion
> instances.  Is it "ok" to dump them all onto the ServletContext?

If the objects need to be shared across multiple JSP pages and/or servlets, the
ServletContext is a natural place to stash them -- that is exactly what it is
designed for.

>
>         Does the ServletContext provide for any kind of bean management
> (e.g., caching)?  If not, then is the standard approach to write my own
> MultipleChoiceQuestionManager, stick the beans in there, and then stick
> the manager in the ServletContext?
>

Think of the servlet context attributes as a Hashtable with a little bit different
method names.  The thing that's probably going to matter most in your example is
the fact that every object you store here needs to have a unique key.  So, you
would need to either manufacture unique keys "multiple.choice.question.1" through
"multiple.choice.question.200" for the individual questions, or wrap them in a
manager bean under a key like "multiple.choice.questions".  For 200 of them, I'd
probably choose that approach, which also allows your manager to have some other
useful logic ("grab me the set of questions that goes on page 3 of the
questionnaire").

>
>         Thanks!
>         Willie Wheeler
>         [EMAIL PROTECTED]
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to