On Sun, 15 Apr 2001, Calvin Yu wrote:

> Hi,
> 
> I apologize in advance if this question has been asked
> before, but I've search the mail archives and docs and
> haven't come up with an answer.
> 
> Is there a place to specify system-level properties in
> Struts?  For example, if the the Model components
> needed to retrieve environment related properties
> (remote server host and port, location of
> initialization files, etc), where would we get them
> from?  I saw the 'application' initialization
> parameter, but that didn't seem to be the same context
> of properties I'm trying to retrieve.
> 

One option to consider would be to use "context initialization
properties".  These are configured in your web.xml file:

  <context-param>
    <param-name>myparam</param-name>
    <parram-value>The value to be retrieved</param-value>
  </context-param>

and you can retrieve this from within a servlet by calling:

  String paramValue =
   getServletContext().getInitParameter("myparam");

> Another way to ask the question would be, where is the
> equivalent of overriding init() in HttpServlet to
> initializing the system?  Is subclassing ActionServlet
> the preferred way?
> 

There's nothing wrong with subclassing ActionServlet as well, and
overriding the init() method.  Just be sure you call super.init() so that
the standard initialization gets done.

This approach would be useful if you needed to dynamically construct an
aobject that you wanted to make available.  For example (assuming for the
moment that Struts did not support connection pools), you might do this in
your overridden init() method:

        ConnectionPool pool = new ConnectionPool(...);
        getServletContext().setAttribute("pool", pool);

to make a connection pool available as a servlet context attribute.

> 
> Calvin
> 

Craig

Reply via email to