I'm trying to do the same thing here, but I'm not sure on a few
of the details.
I've got a servlet called DatabaseContainer, which will handle all
the database connections and populating Beans to send back
to the Actions.
What I can't work out is, once I've get the DataSource, how does the
Action know about the DatabaseContainer? At the moment I've
got
getServletContext().setAttribute("DatabaseContainer", this);
and so in the Action, I can call
DatabaseContainer database = (DatabaseContainer)
servlet.getServletContext().getAttribute("DatabaseContainer");
But this doesn't seem right. Since Craig doesn't like singleton objects
hanging around, and I don't feel like I want to extend ActionServlet,
this seems like the only way (since getServlet() is depreciated in the
2.2 spec).
Any ideas?
>> The problem I'm facing is a bit diffrent as I want to access the
>> Connection Pool from a servlet that is started upon startup
>> of the servlet engine (similar to the struts example application).
>> In order to be able to access the DataSource, I tried to subclass
>> the ActionServlet class and to access the data source that way.
>> However, my servlet engine (Tomcat 3.2.1) complains that it is unable
>> to start this new Action servlet...
>>
>> Any ideas how to solve this problem?
>>
>There are three things you will need to do:
>
>* Make sure that both the Struts controller servlet and your own
> servlet are marked <load-on-startup>.
>
>* Use values for the <load-on-startup> attribute that cause the
> Struts controller servlet to be initialized first (for example, use a
> "1" as the value for the controller servlet, and "2" for yours).
> I'm not positive that Tomcat 3.2 respects this, but it is supposed to.
>
>* The Struts controller servlet makes the data source it initializes
> available as a servlet context attribute, as well as available via a
> method call. You can therefore grab it by calling:
>
> DataSource ds = (javax.sql.DataSource)
> getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
>
> in any other servlet (or JSP page) that is part of the same web app.
--
Kumera - a new Open Source Content Management System
for small to medium web sites written in Perl and using XML
http://www.cyber4.org/kumera/index.html