• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Reading a property file from WEB-INF/conf from a servlet

Hello All,

This is a pretty basic question. I want to know the standard way by which a properties file in the WEB-INF/conf can be retrieved by a servlet. That is the way in which it has the minimum dependencies with the appserver (i.e the directory in which the webapps is located, the make of appserver etc.)

I have used the init-param tags, but I had to give the full path (i.e C:\\Apache..) as the param value.

TYA,
QMS
0
sperin
Asked:
sperin
  • 4
  • 3
  • 2
  • +1
1 Solution
 
CEHJCommented:
Try

URLConnection conn  = new URLConnection("/WEB-INF/conf/x.properties");
0
 
armoghanCommented:
Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/x.properties");
0
 
objectsCommented:
try:

Properties props = new Properties();
props.load(context.getResourceAsStream("/WEB-INF/conf/x.properties");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Please tell us which work and which don't before accepting sperin
0
 
objectsCommented:
> Please tell us which work and which don't before accepting sperin

I think you're supposed to tell sperin what works :-D
0
 
objectsCommented:
Thanks sperin :)

Let me know if you have any further questions.
0
 
CEHJCommented:
!?
0
 
sperinAuthor Commented:
Will tell you chaps about it. I was aware of a ServletContext object, so I too a wild guess and accepted the reply from objects. Now if that does'nt work, well my bad luck :)
0
 
CEHJCommented:
LOL. Aside from rudely ignoring my request, you'd have thought from your point of view it might be just slightly useful to check the answers before making a choice.
0
 
armoghanCommented:
:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now