• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Uploading outside of the Context

 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely you can do it. Simply write the file to the desired location , provided it's on the same server as the application.
 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic