[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: placing the properties file in tomcat
Kamesh,
Thanks for shedding some light, but now i have a few more questions. Please
bear with me. you can possibly show me the first few steps of how i should
approach my problem. I am already using the application.resources file for my
displaying errors, although i must admit it's inner working i have yet to fully
understand. anywho, now i would like to make the use of another properties file
that stores things like paths to certain files, server name etc. These
obviously i need at various points in the application. let this property file
be app.properties. from what i understood, i can place this file in the
/WEB-INF/classes folder and i my entry for it in the web.xml will be something
like
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>app.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I don't know what to substitute servlet-name and servlet-class with. and again,
how do i access these properties from my beans and jsps.
I did look at the java.util.ResourceBundle, but that didn'tdo much except for
give me a conceptual understanding of the usage of resourcebundle.
i think an explanation on this will greatly clear my doubts, and i will be very
grateful,
Thank you
--- Kamesh Challa <kamesh@netexpress.net> wrote:
>
> Poorav,
> If I understand it correctly you want to understand where/how you'd use
> properties file within your STRUTS based application.
>
> If so.. read ahead...
>
> One of the frequent uses of property files within STRUTS FRAMEWORK is to
> customize/standardize error messages across the application.
>
> Let's take an example of defining system wide error messages for clarity.
>
> You'd have to do 4 basic things to accomplish this:
>
> 1. Define error messages in a property file as key value pairs (The usual
> way;-
> )).
>
> Eg: Say you've ApplicationResources.properties file that had the error
> messages
> defined
>
> error.last_name.required=<li><b>Last name</b> is required</li>
>
> Note: Generally HTML tags are included along with the error messages to be
> prominent.
>
> 2. Use the error messages to populate the
> org.apache.struts.action.ActionErrors
> object in case of validation fails in your Application Action Form via the
> validate method.
>
> Eg: You may do something like this in your application Action Form in the
> validate method (per say)
>
> if (last_name is equal to null || some other condition) {
> errors.add("last_name",
> new ActionError("error.last_name.required"));
> }
>
> 3. Define the property file to be available for the framework as the servlet
> init parameter within web.xml file:
>
> Eg: The way you would define the property file is to mention within the
> action
> servlet tag.
>
> <servlet>
> <servlet-name>action</servlet-name>
> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
> <init-param>
> <param-name>application</param-name>
> <param-value>org.XXX.YYY.ZZZ.ApplicationResources</param-value>
> </init-param>
>
>
> 4. Of course you'd be using the <html:errors/> tag in your front end jsps to
> pull the error messages out of the errors object.
>
> This is a simple overview of HOW property file is used. There are tons of
> varieties of usage.
>
> While using property files just remember "load 'em once on startup and use
> 'em
> over and over".
>
> Check out java.util.ResourceBundle.
>
>
> HTH....
>
> Thanks and BR,
> --Kamesh Challa
> Yash Technologies Inc.
>
>
> Quoting Poorav Chaudhari <pooravc@yahoo.com>:
>
> > I have a feeling i am missing the jist of how to use properties. I read the
> > short tutorial on using properties to manage program attributes. but in
> that
> > it
> > is explained with the use of a standalone application. The use and
> > implementation of properties in a servlet environment seems to be a
> > completely
> > different ball game. my application is specifically in struts framework.
> > now
> > the properties that i define in the properties file, will be used through
> > out
> > the application. can i find some sort of discussion on this online?
> > something
> > that will help me clarify this confusion? Thanks.
> >
> > Poorav
> >
> >
> > --- Calvin Yu <cyu77@yahoo.com> wrote:
> > >
> > > Here's how you load it up as a Properties object:
> > >
> > > 1. ServletContext.getResourceAsStream("/WEB-INF/classes/foo.properties");
> > >
> > > 2. Object.getClass().getClassLoader("foo.properties");
> > >
> > > Calvin
> > >
> > >
> > > On Tue, 1 Apr 2003 12:28:34 -0500, Kamesh Challa <kamesh@netexpress.net>
> >
> > > wrote:
> > >
> > > > Couple of methods. 1. Use ResourceBundle rBundle =
> > > > ResourceBundle.getBundle("<your property file name>");
> > > > rBundle.getString("<Your property name>");
> > > >
> > > > 2. Use:
> > > > init parameters within your web.xml and use it. (Struts applications
> are
> >
> > > > classic examples)
> > > >
> > > > I remember some examples within the samples given under tomcat. Check
> it
> >
> > > > out.
> > > >
> > > > HTH...
> > > >
> > > > Thanks, --Kamesh Challa
> > > > Yash Technologies Inc.
> > > >
> > > >
> > > > Quoting Poorav Chaudhari <pooravc@yahoo.com>:
> > > >
> > > >> For my web application, i have created a properties file. It is placed
> >
> > > >> in
> > > >> the
> > > >> WEB-INF/classes folder. to test the properties file i also created a
> > > >> small
> > > >> command line program. that worked fine, i was able to print the values
> >
> > > >> of
> > > >> properties. but when i run the web app on tomcat, i get an error
> > saying
> > > >> that
> > > >> the properties file cannot be found. what am i missing.
> > > >>
> > > >> Thank you in advance.
> > > >>
> > > >>
> > > >> =====
> > > >> Poorav Chaudhari
> > > >>
> > > >> __________________________________________________
> > > >> Do you Yahoo!?
> > > >> Yahoo! Tax Center - File online, calculators, forms, and more
> > > >> http://platinum.yahoo.com
> > > >>
> > > >
> > >
> > >
> > >
> > > --
> > > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
> > >
> >
> >
> > =====
> > Poorav Chaudhari
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Tax Center - File online, calculators, forms, and more
> > http://platinum.yahoo.com
> >
=====
Poorav Chaudhari
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com