my dog learned polymorphism
The moose likes Servlets and the fly likes web application - property file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "web application - property file" Watch "web application - property file" New topic

web application - property file

Ann Kanu
Ranch Hand

Joined: Feb 01, 2004
Posts: 30
I am trying to read all the properties from an application property file into a java class which is part of a web application deployed on weblogic. I am currently hardcoding the location of the property file which holds parameters necessary for my application like email id of the application administrator etc. I use these properties in some of my classes which implement business logic. If I am using parameters in a servlet, I can get it via the init() method from web.xml. But how do I retrieve parameters which are not used in a servlet without hardcoding the location of the file which holds these parameters. Is there a better way to obtain the location of this property file.
Jayson Falkner
Ranch Hand

Joined: May 07, 2001
Posts: 57
Everything in your web application should be able to get at the ServletContext object, so you can always try to encode information in the web.xml parameters. Or alternatively, you can use the ServletContext object to resolve the location of a file in your web application, e.g. your property file.
However, if you want to use regular Java property files you can as well. Simply put the '.properties' file in your WEB-INF/classes directory of your web application. It will then be in the class path of your application.

Jayson Falkner<br /><br />Author of <a href="" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
I agree. Here's the link:
subject: web application - property file
It's not a secret anymore!