Solved

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

Posted on 2004-09-22
10
256 Views
Last Modified: 2013-11-24
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
Comment
Question by:sperin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12121662
Try

URLConnection conn  = new URLConnection("/WEB-INF/conf/x.properties");
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12121673
Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/x.properties");
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 12121683
try:

Properties props = new Properties();
props.load(context.getResourceAsStream("/WEB-INF/conf/x.properties");
0
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12121709
Please tell us which work and which don't before accepting sperin
0
 
LVL 92

Expert Comment

by:objects
ID: 12121720
> Please tell us which work and which don't before accepting sperin

I think you're supposed to tell sperin what works :-D
0
 
LVL 92

Expert Comment

by:objects
ID: 12121756
Thanks sperin :)

Let me know if you have any further questions.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12121758
!?
0
 

Author Comment

by:sperin
ID: 12121805
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12121849
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12121869
:)
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question