Mike wrote:
> My question is how do I maintain session state when using HTML, Servlets and EJB's?
>
> Scenario:
> 1) An HTML client(view) invokes a servlet. 2) The servlet(controller) calls an EJB
>Session bean (Model). 3)The Servlet sends a response back to the client and
>terminates. The HTML client invokes the servlet to do something
> else, and so on.
>
> Question:
> 1) How do you maintain a reference to the Session Bean once the Servlet destroy()
>method is called?
First off, the destroy() method is not going to get called on every request ... it is
only going to get called when the servlet engine wants to unload the servlet, or shut
down. Whether HttpSession information (see next
paragraph) gets maintained across server restarts is dependent on which servlet engine
you are using.
The best way to maintain references to any objects (including EJBs) is to stash them
in an HttpSession associated with the current user. See the Servlet API spec for
discussions of how these things work, but they overcome
the stateless nature of HTTP communications.
One design issue to keep in mind -- you will want to make sure you complete your EJB
transactions (if your EJB session bean is transactional) before returning to the
client. Leaving a transaction open over human-interaction
intervals (seconds to minutes) leads to scalability difficulties, because open
transactions consume server-side resources while the user is thinking or typing.
Craig McClanahan
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".