I'm trying to use an external folder to store the images for my Java EE 6 project. I'm using Glassfish 3.1.2. I created the the sun-web.xml I found from this post:
Glassfish 3 - Loading images from a static server
which is also included here:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app>
<property name="alternatedocroot_1" value="from=/imgs/slideshow/* dir=c:/users/jonathon/desktop/images" />
<property name="alternatedocroot_2" value="from=/imgs/feed/* dir=c:/users/jonathon/desktop/images" />
<property name="alternatedocroot_3" value="from=/imgs/question/* dir=c:/users/jonathon/desktop/images" />
</sun-web-app>
While I don't plan on keeping it on my desktop, I'm just trying to test this before I use this on my server. On my page I use this implementation to display the image:
<div class="item">
<h:graphicImage value="/imgs/slideshow/${imgs}" />
</div>
However I only ever get a blank image. I made sure the directory is correct (If you don't have an existing directory you get an exception on loading the server)
I think a more clarified question is what is the proper way to use external image folders, and how, if possible, do you write to those folders?
You're path will be appended with the from
value. Your images will be requested in for example c:/users/jonathon/dektop/images/imgs/slideshow*
. Has been some trouble for me too in the past. Hope this will get you going.
You don't need the docroot to write to this folder. You can just make use of:
String path = new StringBuilder("c:")
.append(File.separator)
.append("users")
.append(File.separator)
.append("jonathon")
.append(File.separator)
.append("desktop")
.append(File.separator)
.append("images")
.append(File.separator)
.append("imgs")
.append(File.separator)
.append("slideshow")
.append(File.separator)
.append("myfile.jpg")
.toString();
File file = new File(path);