Adam Vernon wrote:
> Craig,
>
> If your ConnectionPool (or other shared collection) lives in the servlet context,
>how would your
> non-serlvet objects use the ConnectionPool? I assume you would have the servlet
>pass the
> ConnectionPool as an argument to the non-servlet object.
>
Yep, that is pretty much the way I would do it.
In fact, my recent servlet+JSP designs have tended to include only a single servlet
which knows how to
dispatch to action procedures based on how it interprets the "path info" part of the
request URI. I've
defined an interface called Action for these action procedures to implement, like this:
public interface Action {
public void perform(HttpServlet servlet,
HttpServletRequest req,
HttpServletResponse res)
throws IOException, ServletException;
}
In other words, I pass along a reference to the servlet itself to each action
procedure. That way, the
action procedure can do things like look up initialization parameters
(getServletConfig().getInitParameter()), get servlet context attributes, and access
the servlet logging
capabilities -- all without having to do anything else special. If an action method
needs to pass the
connection pool to some other object, it does so in an explicit argument.
For JSP pages, servlet context attributes are directly accessible as beans with
"application" scope.
>
> In my scheme, there is a layer between the servlets and the database, which I call
>the dbobject
> package. This package implements generalized methods for handling insert, query,
>etc for various
> datatypes. For each Oracle table, I inherit a new class, writing only a
>constructor, gets and sets.
> My DbObject class handles the rest.
>
> The servlet uses the dbobject, never touches jdbc, and can not even see the
>protected ConnectionPool.
>
> Do you see any potential drawbacks to my approach?
>
It sounds like you could just store your dbobject, instead of a generic connection
pool, as a servlet
context attribute. Then, you've got shared access to it.
>
> Thank you for your valuable insights,
>
Nada problem.
>
> Adam
>
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