[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: placing the properties file in tomcat
What Kamesh is suggesting is by no means a breakage from the Struts
framework. Struts does not define how your model is suppose to work, just
the view and controller. It sounds like the type of properties you're
trying to load aren't really view or controller type properties.
There are a lot of Struts compatible libraries out there that uses the
Properties objects outside of what Struts provides. I don't consider that
as being counter to the Struts framework.
Unless you really need internationalization, I really wouldn't suggest
using a ResourceBundle though. It has this really annoying way of throwing
exceptions when a property doesn't exist.
If you want to stick within the 'Servlets' framework, you can extend
ActionServlet and do the following in init():
public void init() throws ServletException {
Properties props = new Properties();
try {
props.load(getServletContext().getResorcesAsStream("/WEB-
INF/classes/application.properties"));
getServletContext().setAttribute("properties", props);
} catch (Exception e) {
throw new ServletException("Error loading properties", e);
}
}
[watch out, I didn't do a compile check on this code]
Then you can always get the properties object from ServletContext.
Calvin
On Thu, 3 Apr 2003 07:32:12 -0800 (PST), Poorav Chaudhari
<pooravc@yahoo.com> wrote:
> Kamesh,
>
> I am not sure how the misunderstanding occured, but my application is
> based on
> struts framework. but what you suggested for servelts also seems quite
> logical
> to me and can be used within struts, although i might be breaking out of
> the
> 'proper' framework. so i guess now i should ask, will i break a big
> struts norm
> in using your third suggestion. and again if i want to go the init-param
> way.
> can you once more explain how i will use the properties globally.
> Essentially
> the same solution that you have provided here but in the struts
> framework.
>
> once again, please bear with me. this is taking longer to sink in than i
> thought and hoped. i am reading up on servlets and struts to brush up
> some of
> my fundamentals.
>
> thank you
> --- Kamesh Challa <kamesh@netexpress.net> wrote:
>> Poorav, The init-param was basically for the Struts framework but not
>> part of the servlet parameters. So, basically you're looking for an
>> alternative to access the global
>> property file across the board. Correct??
>>
>> Well, there are many methods to configure the global properties. Let's
>> discuss some of the them for better understanding. 1. You could
>> configure them within the property xml files of the servers (weblogic or
>> tomcat or what ever your server may be) and get the values from the
>> context. (I would not suggest this method) 2. Create an interface class
>> and store the values within the interface as
>> final variables and hence available where ever you want. (I would not
>> suggest this method too. Not scalable at all) 3. One of the better
>> methods I'd suggest: - Create the external property object as you've
>> created already. - Create a class which makes use of the ResourceBundle
>> to load the properties in the constructor of the object
>> - Have static methods to get the property values from the resource
>> bundle.
>> - Use this class where ever you want.
>>
>> This should be simple enough.
>>
>> If you want to know more about ResourceBundle class
>> http://java.sun.com/docs/books/tutorial/i18n/resbundle/concept.html
>> and how to use with property file at:
>> http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html
>>
>>
>> Hope this is of some help...
>>
>> Thanks and BR, --Kamesh Challa
>> Yash Technologies Inc.
>>
>
>
> =====
> Poorav Chaudhari
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - File online, calculators, forms, and more
> http://tax.yahoo.com
>
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/