File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to access properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to access properties file" Watch "how to access properties file" New topic

how to access properties file

Gerome Kawa
Ranch Hand

Joined: Dec 05, 2002
Posts: 61

I need to use a properties file to replace variables in a Java program and a servlet.

Eg. of Java program:

The servlet:

I want to put the stuff between @xyz@ in the above programs in a properties file and access them - how do i do it?

I want to stuff @xyz@ in the servlet to come from a init-param of the servlet defined in web.xml .

Where should I put the properties file ?
How do i access it(the variavles in the properties file) from java program?
Do i need to put the properties file in the classpath?


[EDIT code tags added by Dave]
[ February 10, 2005: Message edited by: David O'Meara ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Third item on the page. It should answer all of your questions.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Here's a pointer for you: SimpleDateFormat isn't thread safe! It should be but is not.

Don't make it a static final, create a new one each time you need it, or as a method variable (NOT an instance variable, this is a servlet we're talking about).

Just be glad you're not learning this the hard way!
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

and after 56 posts it's time for you to experiment with UBB's code tags
I agree. Here's the link:
subject: how to access properties file
It's not a secret anymore!