• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Properties File in struts

 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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
 
Manuel Sanchez Iba´┐Żez
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
 
Aash Patel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic