Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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