The ActionServlet loads the MessageResources via the initApplication()
method.  One should really request the MessageResources from the
ActionServlet to eliminate extra I/O calls.  In general, Action classes
extend the ActionForm and can access these via the following call:

public class MyAction extends Action {

  public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException (

    MessageResources recources = this.getServlet().getResources();

  }


Note, that an Action can gain access to the servlet via the call to the
getServlet() method.  See the Action class.  Once you have a reference
to the ActionServlet you can get the MessageResources via a call to the
getResources() on the ActionServlet.  Though a direct call to
getResourceAsStream() works, it's not as effective since the
ActionServlet has already loaded these values.

Note, the ActionForm also has access to these resource since the
ActionForm has a method getServlet().  One the MessageResources is
loaded in the ActionServlet most classes have access to this via the
ActionServlet.

Hope this helps,
Steve

Mike Olivieri wrote:
> 
> A similar approach is using the getResourceAsStream() method from any class.
> 
> InputStream propFileStream =
> getClass().getResourceAsStream("/com/companyname/appname/app.properties");
> Properties props = new Properties();
> props.load(propFileStream);
> 
> This works well for any kind of application, and will search the classpath
> rather than the filesystem for the properties file.
> 
> Sometimes, there can be an extreme proliferation of properties files. In a
> large app, you'll have potentially hundreds of properties. Make sure that your
> properties keys are descriptive enough that you could potentially combine them
> into one properties file. You wouldn't want to just use:
> driver=oracle.jdbc.drivers.OracleDriver
> Instead, use
> appname.subsystem.jdbc.driver=oracle.jdbc.drivers.OracleDriver
> 
> And finally, Mark is absolutely right about not mixing logic in your tiers.
> Make sure that any business logic you have is encapsulated in classes that are
> used by the Action class - don't put the business logic directly in the Action
> class. It's not really much more typing, and will actually be easier to debug
> and support... and reuse!
> 
> --- Mark Rines <[EMAIL PROTECTED]> wrote:
> > Scope, scope, scope. Once you're in your Action class, you are in the
> > business logic scope of your application. Your business logic should have
> > nothing to do with Struts, or any other non business related architectural
> > implementation ( such as Swing, JAAS, etc...), architecturally speaking. So,
> > use the classes and methods used for manipulating any other properties file,
> > which is just what the ApplicationResources.properties file is, no more, no
> > less. For more info see the Properties class , and the supporting classes
> > Property*. Reading can be as  easy as:
> > ...
> > PropertyResourceBundle p = new PropertyResourceBundle( new
> > FileInputStream("ApplicationResources.properties") );
> > ...
> > String propertyValue = p.getString("myKeyName");
> > ...
> >
> > Hope this helps.
> > Mark
> > ----- Original Message -----
> > From: "Michael Mehrle" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Sunday, January 27, 2002 12:01 AM
> > Subject: Can I directly access properties in my ApplicationResources file?
> >
> >
> > > Okay, I'm in my Action class and would like to access some application
> > > specific configuration settings stored in my ApplicationResources.config
> > > file . What method do I call from my Action subclass in order to get to
> > > those? I have been looking all over the place and can't make sense out of
> > > this...
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >
> 
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

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

Reply via email to