Solved

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

Posted on 2004-09-22
10
253 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 52
custom annotations 9 38
configure dependency in POM for new database 3 25
How do I remove an object from a 3 23
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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