aspose file tools*
The moose likes Servlets and the fly likes Uploading outside of the Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Uploading outside of the Context" Watch "Uploading outside of the Context" New topic
Author

Uploading outside of the Context

Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
Hi there,

I want to upload images to a directory that is outside of the current context, the same folder with the .WAR file. This way, when the WAR is updated, the images will remain on the server.
How can I reach the path to the parent directory of the context?

Thanks for your help,
Murat
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Surely you can do it. Simply write the file to the desired location , provided it's on the same server as the application.


Programming is about thinking, NOT coding
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
Hi,
I want to get that physical path dynamically so that if the path changes, i should not update the code.
Thanks,
Murat
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Murat Balkan wrote:Hi,
I want to get that physical path dynamically so that if the path changes, i should not update the code.
Thanks,
Murat


You have two options

1> Use a realtive path inside the contextpath. You cannot go beyond root of your web/application server, with this approach
2> use absolute path.

Now you said, you want dynamic path , what's your logic about the dynamic path?
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
Hi
can you give an example to the first one?
I want to find the path to the webapps directory.
Regards,
Murat
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Murat Balkan wrote:Hi
can you give an example to the first one?
I want to find the path to the webapps directory.
Regards,
Murat


use
this will take you to the root of your application
Murat Balkan
Ranch Hand

Joined: Sep 10, 2002
Posts: 127
Hi,
Thanks for the reply.
I was able to reach the webapps real path via:

File dir = new File(request.getServletContext().getRealPath("/"));
System.out.println(dir.getParent());

Regards,
Murat
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Murat Balkan wrote:Hi,
Thanks for the reply.
I was able to reach the webapps real path via:

File dir = new File(request.getServletContext().getRealPath("/"));
System.out.println(dir.getParent());

Regards,
Murat


Yes that's what I said
Vishal shaw wrote: this will take you to the root of your application
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Uploading outside of the Context