David Chisholm wrote:

> ----- Original Message -----
> From: Mike Engelhart <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, September 01, 1999 8:38 AM
> Subject: Re: Passing Connection Objects from servlets to JSP??
>
> > > This is not a good practice. Contents of sessions should be
> > > serializable, and connections are not. Imagine a distributed servlet/jsp
> > > cluster!
> >
> > While i agree that stuffing java.sql.Connections into a session isn't a
> good
> > idea, where does it say that contents of session should be serializable?
>
> Check the JSDK 2.2 spec.  I believe that it specifies that anything put into
> a Session must be serializable else you will get an exception.  This was
> done to allow distributed servlet containers for load balancing.
> David
>

The 2.2 servlet API spec language for this topic (Section 7.7.2) got refined in
the "public release" version currently on the web site, quoted below:

    7.7.2    Distributed Environments

    Within an application that is marked as distributable, all
    requests that are part of a session can only be handled
    on a single VM at any one time.  In addition, all objects
    placed into the session must implement the Serializable
    interface.  The servlet container may thrown an
    IllegalArgumentException if a non-serializable object is
    placed into the session.

The "marked as distributable" thing is a setting in your deployment descriptor
that tells the servlet engine you've programmed this application to work correctly
in a distributed environment -- one of the restrictions being that you can only
put Serializable objects into your sessions.  If you don't set this flag, you
don't have to worry about the restriction (and the servlet engine will not
distribute your web app, even if it supports this feature).

Regardless of this, a session is the wrong place (IMHO) to put a connection pool.
My habit is to store one in the servlet context, as others have suggested, so that
it is available to all servlets and JSP pages in my app.

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