Do this:
OPTION 1
String path = this.getServletContext().getRealPath("../imagens");
File f = new File(path);
String imagensHome = f.getCanonicalPath();
You can then create a Servlet to fulfill the requests in /img_uploader
and deliver the images from:
File imagensRoot = new File(imagensHome);
You should pay special attention to the Mime Type of the images at the time of delivery to the client by assigning the appropriate Content Type.
OPTION 2
Only if your server is running Tomcat 7+ on Linux, UNIX, or Mac OS X
Create a symbolic link using ln -s img_uploader ../imagens
Create a context.xml
file as below:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
This file informs Tomcat via the allowLinking="true"
attribute that it can access symbolic links and deliver content to the client from ../imagens
.
NOTE: In this solution a Deploy script should re-create this symbolic link described above in case it is removed.