Solved

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

Posted on 2004-09-22
10
252 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
Comment Utility
Try

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

Expert Comment

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

Accepted Solution

by:
objects earned 50 total points
Comment Utility
try:

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

Expert Comment

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

Expert Comment

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

I think you're supposed to tell sperin what works :-D
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 92

Expert Comment

by:objects
Comment Utility
Thanks sperin :)

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

Expert Comment

by:CEHJ
Comment Utility
!?
0
 

Author Comment

by:sperin
Comment Utility
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
Comment Utility
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
Comment Utility
:)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now