Hi,

In our ConnectionPool class, we have a static initializer block that
actually gets the connections to the database for the pool. This is called
the very fist time any database is accessed. I would believe the init()
method would be a better place to do this, but during testing, you often
don't need to use the database, for example if your testing a bunch of
static pages, or multi-page forms that dont access the database immediately.
Its up to you. I don't see any reason not to put it in the init method..that
is called when the engine starts and your app is loaded (assuming that
servlet is loaded with the engine).

One thing I think maybe you should think about..unless I didn't quite
understand how you structure your classes. The ideal (well, at least from
what I am gaterhing with all the Model 2 discussion we have been having
here) situation is your controller servlet dispatches to an action class.
That action class would then call a "logic" class to do the work. You would
want to make all use of database in these "logic" classes, not directly in
the controller servlet or in the action classes. Some people use a JavaBean
to do the logic, thus their action class creates the javabean and calls on
it to do the logic. My reasoning is, if you have in mind to move to EJB,
most likely your EJBs would run on a different server than your servlets
(but not always), and the EJBs would be doing the logic, and all the
database connections. Your servlets and action classes would not be using
the database directly, so that is why I am saying its a good idea not to do
it that way now, even if you are not using EJB yet. This is my own
preference from what I have been learning, and it is not wrong to do it
other ways, but IMHO I believe it to be a better approach and separation of
the tiers of code by having a "logic" class use the database connections.

>In a similar vein, how do people handle logging. I wish to have one logger
>class accessible by all classes in my application. This includes the
>Servlets, beans and regular java classes.

My personal preference would be to use a static class, maybe called Logging
or something, and a property file that is loaded in the init() method to
allow for the directory for logging. Again I think there is no perfect way
to do this..its a matter of preference. But I am open to suggestions on both
of these questions as well.


>I've programmed with a proprietary Application Server Web Objects, that had
>one Application class that was accusable by all other classes in the
>application. Here I stored the logging, and any other global services. How
>would I handle this with Servlets, JSP, bean Model 2 architecture.

There is the Application scope for JSP pages, but I myself am not sure how
to access that in a servlet. I think its part of the Config passed to the
ServletConfig init() method (there's that init() method again), and you get
the Context which allows ALL servlets to get/put attributes to it? Anyone
want to verify that for me/us?

Thanks.

===========================================================================
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

Reply via email to