Skip to Content
avatar image
Former Member

Cannot read Property file from JSP in a Web Module Project

I have tried to read the properties file in two ways but am not able to read it because i cannot find the correct path of the properties file.

1st Method :

Properties props = new Properties();

InputStream is =

application.getResourceAsStream(

"test.properties");

if (is != null) {

props.load(is);

is.close();

Enumeration keysEnum = Props.propertyNames();

while (keysEnum.hasMoreElements()) {

out.println(keysEnum.nextElement()) ;

}

2nd Method :

Here "com.sap.package" is the package name and "test" is the Properties file name

ResourceBundlebundle = ResourceBundle.getBundle("com.sap.package.test");

for (Enumeration e = bundle.getKeys(); e.hasMoreElements();)

{

String key = (String) e.nextElement();

out.print((String) e.nextElement());

String s = bundle.getString(key);

request.getComponentSession().putValue(key, s);

}

I cannot read the properties file even when I keep in it the WEB-INF folder.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 22, 2006 at 03:12 PM

    Properties props = new Properties();

    InputStream is = this.class.getClassLoader().getResourceAsStream(/test.properties);

    if(is != null){

    props.load(is);

    }

    Keep the test.properties in the classes folder under the web-inf folder.

    Thanks,

    Tim

    Add comment
    10|10000 characters needed characters exceeded