• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic