• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Uploading outside of the Context

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
It's a tiny ad only because the water is so cold.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic