Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web application - property file

 
Ann Kanu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic