Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP and Properties file

Status
Not open for further replies.

jem122974

Programmer
Nov 1, 2001
114
US
I have a website build with JSP and Java programs. I would like to have a properties file that contains some system information for my Java programs to access. I was hoping I could just put it in the root directory of the site and then the programs would find it. But I'm not sure how to reference the file. I'm doing the following but it is giving me a FileNotFoundException. Also I'd be able to do the same thing on our AS400 server. So where could I put it so the Java programs could access it when they are running on my laptop or on the AS400? And how would I reference it from my programs so I don't have to change the program each time I move it from my laptop to the AS400?

Code:
Properties prop = new Properties();
prop.load(new FileInputStream("system.properties"));
 
Within a JSP, you can call

session.getServletContext().getRealPath("/");

which will give you a relative path on the server to the root of your webapp, eg :

/usr/local/tomcat/webapps/myWebApp

--------------------------------------------------
Free Database Connection Pooling Software
 
A little more longwinded, but another solution none the less ;)

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top