On Sun, 5 Aug 2001, Ted Husted wrote:
> So there is not a way to access the ServletContext attributes without a
> direct link to a servlet or a JSP?
>
Well, you could pass a reference to the ServletContext into your bean, but
that's still requiring a reference to the web tier APIs -- which it sounds
like you're trying to avoid (for good reason).
> The Generic Connection Pool works fine with the dbTags, but they can
> lookup the DataSource through the pageContext.
>
A really cool enhancement to dbtags would be to add the option of looking
up a data source via JNDI. All it would take is an alternative attribute
for the <sql:connection> tag.
> If it were possible, it may also be interesting to be able to tap into
> the ActionMappings and MessageResources that Struts exposes through the
> Application context, from library utilities that are running in the same
> application context, without a direct link to a particular servlet.
>
Unfortunately, from the perspective of the web application, the JNDI
context created for you by the app server is read only, and is configured
solely through container-specific administration.
On the other hand, a few other approaches come to mind:
* (Hard) implement a JNDI context *inside* the web app.
* (Medium) store serialized versions of the Struts application
objects in a JNDI-accessed directory server (or, for that
matter, a JDBC-accessed database). Of course, you've still
got the "chicken and egg" problem of how to gain access to
the directory server or database ...
* (Easy) Use static variables and methods to provide access
to application resources. (Turbine takes this approach
for almost everything). I chose not to do this in Struts
because I've seen lots of people get themselves in trouble
with global variables that are accessible for both read *and*
write anywhere in the app.
> -Ted.
>
Craig
> "Craig R. McClanahan" wrote:
> > You won't be able to use the Struts connection pool directly, but all J2EE
> > application servers (and some servlet containers, such as Tomcat 4) let
> > you configure a connection pool that can be accessed via JNDI. I
> > responded to a similar question with the details of this earlier today, so
> > it should show up shortly.
>