Adam Vernon wrote:
> Hi Craig,
>
> I included some of your discussion below. You talk about keeping the ConnectionPool
>in the
> ServletContext. Why not use a static class interface for the ConnectionPool? Would
>it not be
> available to the JSP pages?
>
> Adam
>
Yes, static variables would be available -- in a JSP page, you could use a scriptlet
to access
these values. I tend to avoid static variables for several philosophical reasons,
however:
* Static variables tend to make me lazy about good
object-oriented design (especially on encapsulization
and information hiding issues). I find that my applications
are better architected if I resist the temptation to
use statics.
* Static variables are available *everywhere* in your
application, not just where you need them to be. This
can make debugging much harder when mysterious
changes to these variables occur. It's like going back
to COMMON variables in the old Fortran days (if that
means something to you, you're probably old like I am :-).
* In particular for JSP pages, you don't get to use the
<jsp:useBean /> mechanism to declare the associated
variable. Since you have to use a scriptlet to declare
it, you're going to find yourself tempted to put business
logic in the JSP pages as well -- which I also try to
avoid in my app designs.
* Static variables are singletons. This is OK if you are
running your app in a dedicated JVM, but what if that is
not the case? What if there is another servlet based app
in the same servlet container, that wants to use the same
static variable to store it's connection pool? In a servlet
and JSP based world, you cannot assume that you will
always have 100% occupancy of the server you run in.
NOTE: The last point becomes more complicated in servlet containers that implement
custom class
loaders -- it may or may not be true, depending on whether the class containing your
static is on
the system class path or not. But the basic issue still remains.
Craig
===========================================================================
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