wood burning stoves 2.0*
The moose likes JSP and the fly likes Need help regarding Server's Real Path. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Need help regarding Server Watch "Need help regarding Server New topic
Author

Need help regarding Server's Real Path.

Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
In my Java Web Application, I need to dynamically create directories and upload files. For that I need the Real Path of the container. I use the following code



these two are working fine when i ran the application in localhost. it returns /home/xen/NetBeansProject/WebApp

but when I upload the project as a war file in my Internet server, it is not working. every times it return null.

Can you give me any suggestion regarding this?? Thank You.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

You can't get the file path into a war file. It's war file... there's no file system!

Besides, you shouldn't be adding files into the web app itself -- how on Earth do you expect to be able to redeploy the app with changes?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Rather than using getRealPath, I would suggest that you find out a directory on the server that your provider lets you write to, and include it as a property in your web app.

ie rather than using the ServletContext getRealPath method, retrieve it from a parameter you have set.

Agreed, it makes the installation of your site more complicated, as you now need to configure an additional piece of information somewhere, but it does have the advantage that you can specify anywhere - not just within the application path.
Possible places to put the property:
- in a properties file under the WEB-INF directory
- in the web.xml as a context property
- in a database
 
jQuery in Action, 2nd edition
 
subject: Need help regarding Server's Real Path.
 
Similar Threads
getRealPath returns null in Linux(Fedora)
How to read a resource file from war file ??
Finding path of a file
getResource & getRealPath
File upload into project structure