One word, eh? ServletContextListener.  Use a ServletContextListener to
load your properties files and pass the name to it via servlet context
parameter.  There are ways to use Struts classes to initialize and
load the data, but I wouldn't recommend it when there are solutions
that are just as effective, but don't rely on Struts.

See also http://www.onjava.com/pub/a/onjava/2001/04/12/listeners.html
or google for ServletContextListener

BTW, this is the approach Spring, MyFaces, and I imagine many other
frameworks and applications use to load their data on startup.

Don

On 12/13/06, Sébastien LABEY <[EMAIL PROTECTED]> wrote:
Thank you Don,

In fact, I don't want to have the name of my properties file to be hard
coded... So I thought about the "key initialization parameters" that allowed
me to set the name of the file and the Java class to load it.
Do you think it is a right way to do it, or maybe should I think about a
Listener like in the MailReader app to load the database?
In one word, what's the best way to do it?

Thanks

On 12/13/06, Don Brown <[EMAIL PROTECTED]> wrote:
>
> If you just need to load a few properties, you shouldn't have to touch
> Struts at all.  Just create a file, say,
> WEB-INF/classes/db.properties, then load it in your Java code via:
>
> Properties props = new Properties();
> props.load(this.getClass
> ().getClassLoader().getResourceAsStream("/db.properties");
>
> and away you go...
>
> Don
>
> On 12/13/06, Sébastien LABEY <[EMAIL PROTECTED]> wrote:
> > Hi all,
> >
> > I'd like to load a file containing the parameters to connect to DB at
> the
> > application startup. In the S2 documentation I read about the "key
> > initialization parameters" (
> http://struts.apache.org/2.x/docs/webxml.html)
> > and so I add the 2 lines <init-param> to my web.xml like this :
> > <filter>
> >         <filter-name>action2</filter-name>
> >         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
> > </filter-class>
> >         <init-param>
> >                 <param-name>config</param-name>
> >                 <param-value>appConfig.xml</param-value>
> >         </init-param>
> >         <init-param>
> >                 <param-name>configProviders</param-name>
> >                 <param-value>
> > app.core.configuration.ApplicationConfigurationProvider</param-value>
> >         </init-param>
> > </filter>
> >
> > The appConfig.xml is the file where I have my configuration, it is
> supposed
> > to be at the root (/WEB-INF/), and the
> > app.core.configuration.ApplicationConfigurationProvider is the class
> > implementing ConfigurationProvider interface as said in the doc.
> > In the init() method of the Provider, I just add "System.out.println
> ("--Init
> > plugin begin--");" but it never appears in the log, and I cannot see
> > anything neither about the xml file nor the Provider.
> >
> > Maybe, I'm totally wrong and there is a better way to load the file
> where I
> > configure my DB connection?
> >
> > I'm a little confused, so any help would be appreciated.
> >
> > Thanks in advance.
> >
> > Sebastien
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to