It's not a secret anymore!*
The moose likes Servlets and the fly likes What should System.getProperty( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What should System.getProperty("user.dir") return when called from a bean ?" Watch "What should System.getProperty("user.dir") return when called from a bean ?" New topic
Author

What should System.getProperty("user.dir") return when called from a bean ?

Celina Joseph
Greenhorn

Joined: Aug 23, 2001
Posts: 24
Okay now, lemme explain the real problem.
I have to load a properties file from a bean.This bean is called from the jsp page.
The properties file is in the same folder as the jsp page.But how do I get the correct path in the bean to load the property file.
If I call the System.getProperty("user.dir"), it gives me the path to the folder before the jsp page.(Not the one where the jsp is).My jsp lies in the following path -
c:\\prgram files\allaire\JRun\servers\default\time
and the path returned by System.get...
is
c:\\program files\JRun\servers\default
.
I don't want to add the folder Time to the path in the code b'coz it may change in different environments.
I have a jsp which is in directory c:\\...default\ccsd.
From this jsp, I call a bean interface which returns the System.getProperty("user.dir").
The returned value is - c:\\....\default instead of c:\\...\default\ccsd.
I cannot understand the logic behind it.
JRun 3.0 is being used.

[This message has been edited by Celina Joseph (edited August 30, 2001).]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

ummm....that probably the root dir of your web application.
haven't tried it, so partly guessing...
Am I right?
Please let me know what the root of your application is....
just curious...
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

I wouldn't even try it. In fact, I think a lot of systems will return a null object, depending on how the server was started and the rest would return something unique to the server - and it MIGHT even change unpredictably as the server processes different requests.
It's not really appropriate here. You're better off starting from a known absolute reference point, which you can pass in as a server parameter.


Customer surveys are for companies who didn't pay proper attention to begin with.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

sounds really scary to even attempt.....
- satya
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Y'know, on reflection, there's a larger issue here. You really shouldn't put control information in a location from which content can be served. Bad Guys like to dig around the normal access mechanisms and abuse your hard work.
If you put the properties file in the classes directory you can use the java Resource functionality to access it without having to know its absolute location.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What should System.getProperty("user.dir") return when called from a bean ?