• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Properties File in struts

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please can someone help me how to load a properties file of my own in struts and use it.

I am using the following code in action classs,

Properties prop=new Properties();
InputStream is=ClassLoader.getSystemClassLoader().getResourceAsStream("\\phaseOneEAR\\web\\WEB-INF\\classes\\TabMapping.properties");
prop.load(is);
String s=prop.getProperty("AccountSummary");

Is it the right approach,shd I set any param in web.xml
Please held me
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my code:

Properties config = new Properties();
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream("db.properties");
config.load(is);

db.properties is in /WEB-INF/db.properties
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I did it:

String s = new String();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("ApplicationResources.properties");
Properties defaultProps = new Properties();
if( in != null ) {
defaultProps.load(in);
in.close();
dbConfigInfo = new ArrayList();
Enumeration i = defaultProps.keys();
while(i.hasMoreElements()) {
String tmp = (String)i.nextElement();
dbConfigInfo.add(new DbConfigInfoBean(tmp, defaultProps.getProperty(tmp)));
}
}
else {
log.fatal("Error: Couldn't locate ApplicationResources.properties file");
}

Make sure the above code is within try/catch blocks. DbConfigInfoBean is a bean of variables with getter and setter methods.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic