• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Uploading images to webapp/images folder

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick question...

Is there a way of saying I want to upload images to my webapp's images folder, without having to put the full folder path in? Because I don't know what the full path will be.
On my machine it's C:\server\Tomcat\webapps\myapp\images but on a Test machine which is Linux it will probably be something like /usr/local/tomcat/webapps/myapp/images

So what I'm looking for is a way I can just hardcode the /images/XXX bit and use 'something' so that the app knows to put it under it's own folder.
i have looked at the getContext() and things like that, but it just ends up creating a folder at C: like: C:\myapp/xyz...

Cheers
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's where ServletContext.getRealPath comes in with a parameter like "/images/".
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
org.apache.struts2.ServletActionContext.getServletContext().getRealPath("/")



(Sorry forgot to mention Struts2)
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am using struts -1.2 and same things i did by using as
String file=gerServelet().getservlerContexPath().getRealPath();
it will work
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic