aspose file tools*
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 Spring in Action this week in the Spring 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: 61413
    
  67

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: 1018
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help regarding Server's Real Path.