0

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?

Community
  • 1
  • 1
user1760412
  • 137
  • 12

1 Answers1

0

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);
Menno
  • 12,175
  • 14
  • 56
  • 88
  • If i have a glassfish-web.xml should it be in there? I just realized that that might be a problem as well. – user1760412 Apr 19 '13 at 05:57
  • I guess it does, I noticed an error when loading and it says the sun-web.xml is being ignored. I put it in the glassfish-web.xml as a child of and it worked beautifully. How do you write to it though? – user1760412 Apr 19 '13 at 06:08
  • Depending on which version of Glassfish you are using. `sun-web.xml` for the version of Glassfish as supported by Sun. `glassfish-web.xml` for the opensource version. In case of the opensource version, you shouldn't use the brackets of `` either. There's a simular name for it with the opensource edition (don't know it, will search a bit). – Menno Apr 19 '13 at 06:08
  • @user1760412: Updated my answer for the `writing`-bit. – Menno Apr 19 '13 at 06:12
  • So I don't need to do some fancy way to get the external location when saving? Just the normal file path? I'm pretty new to Java EE. – user1760412 Apr 19 '13 at 06:21
  • Yes. You can simply write to your disk like you would normally. – Menno Apr 19 '13 at 06:24