File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Using Properties File in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using Properties File in struts" Watch "Using Properties File in struts" New topic

Using Properties File in struts

yash Vi
Ranch Hand

Joined: Jul 17, 2005
Posts: 41
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\\");
String s=prop.getProperty("AccountSummary");

Is it the right approach,shd I set any param in web.xml
Please held me

Thanks for your reply and time.<br />Windows 2000,j2sdk1.4.2_08
Manuel Sanchez Iba�ez

Joined: Jul 12, 2005
Posts: 20
This is my code:

Properties config = new Properties();
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream("");
config.load(is); is in /WEB-INF/
Aash Patel

Joined: Sep 14, 2005
Posts: 24
This is how I did it:

String s = new String();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("");
Properties defaultProps = new Properties();
if( in != null ) {
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 file");

Make sure the above code is within try/catch blocks. DbConfigInfoBean is a bean of variables with getter and setter methods.
I agree. Here's the link:
subject: Using Properties File in struts
It's not a secret anymore!