?
Solved

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

Posted on 2004-09-22
10
Medium Priority
?
257 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 150 total points
ID: 12121683
try:

Properties props = new Properties();
props.load(context.getResourceAsStream("/WEB-INF/conf/x.properties");
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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

Technology Partners: 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!

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…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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