Andrew Beacock wrote:
> John,
>
> > Are there any downsides to putting objects in the HttpSession Object (as
> > opposed to strictly using request/response).
>
> All session-bound objects have to serialisable (which can cause
> problems), due to the session constantly saved and restored.
In servlet API 2.2, the requirement to be serializable is only when you include the
<distributable> element in your web application deployment descriptor, which
indicates that your application is programmed to operate in a distributed
environment. In general, whether or not session information is ever saved and
restored is a feature of each particular servlet container -- check the docs on
yours to know what is supported and what is not.
>
> Therefore if you have large data objects, it would be better to store
> references to the these objects rather than the objects themselves.
> Also stay away from binding SQL connections in the session, as this also
> can cause some nasty db access problems.
>
> > Are there any guidelines/Best Practices discussing (or advocating) minimal use
> > of HttpSession object as a placeholder for object data (ex. beans)?
>
> If you are using the model2 jsp->servlet->jsp concept, then it's best to
> bind objects to the request and forward(), and only bind to the session
> for things that are constantly accessed, e.g. member's name, id, etc.
>
I follow a slightly different rule in my own application development -- if I need
something for longer than just the current request, I store the data, or a "pointer"
to the data, in the user's session. Otherwise, I use request attributes. The
decision between storing the data or a "pointer" to the data (i.e. a way to
reconstruct it) depends on the size of the stuff that would need to be stored as
compared to the memory available on the server, the number of simultaneous user
sessions that are active, and so on. If I have (relatively) lots of available
memory, and/or it would take a long time to reconstruct the data next time I needed
it (say, a very expensive database query) I will tend to keep the data in the user
session even if it is fairly large -- but I will try to get rid of it as quickly as
possible to make the memory space available for garbage collection and reuse.
>
> Any comments?
>
> Andrew Beacock
> Software Team Leader
> InterVoiceBrite Ltd.
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets