This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Uploading images to webapp/images folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Uploading images to webapp/images folder" Watch "Uploading images to webapp/images folder" New topic
Author

Uploading images to webapp/images folder

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
That's where ServletContext.getRealPath comes in with a parameter like "/images/".


Ping & DNS - updated with new look and Ping home screen widget
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
org.apache.struts2.ServletActionContext.getServletContext().getRealPath("/")



(Sorry forgot to mention Struts2)
Chandan Sarma
Greenhorn

Joined: Oct 04, 2011
Posts: 14
Hi i am using struts -1.2 and same things i did by using as
String file=gerServelet().getservlerContexPath().getRealPath();
it will work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Uploading images to webapp/images folder
 
Similar Threads
How to set context path in Tomcat 5.5.13
Basic Tomcat question
serve static HTML from app context rather than ROOT
Html Input to oracle through servlet and JSP output
temp location