问题描述:

I need to access some images with this URL http://localhost:8080/static/img1.jpg

The images are in "/home/andrea/Documents", the application context is "/". I'm using GlassFish 4.1.1.

In the /WEB-INF directory of project I've got the following: (glassfish-web.xml)

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">

<glassfish-web-app>

<parameter-encoding default-charset="UTF-8" />

<property name="alternatedocroot_1" value="from=/static/* dir=/home/andrea/Documents" />

</glassfish-web-app>

The problem is that, the file is not found.

What did I miss?

Is there another way to define alternatedocroot` or map a virtual directory outside the project?

网友答案:

I've resolved the problem reading this post: http://glassfish.10926.n7.nabble.com/unable-to-get-working-alternate-docroots-td40978.html

Unfortunately the documentation is not so clear, I try to explain how I solved my problem

The dir value is the base directory of your alternatedocroot, so you must put full path specified for the value frominto the base dir of alternatedocroot. Therefore in my case the real structure is /home/andrea/Documents/static (Remember to insert "/" at the end of dir value).

glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <parameter-encoding default-charset="UTF-8" />
    <property name="alternatedocroot_1" value="from=/static/* dir=/home/andrea/Documents/" />
</glassfish-web-app>

My exigence

My exigence is to have a separate directory to upload images separated from the ".war" archive. The solution I've found is insert the images in docroot directory of glassfish domain1 directory

glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <parameter-encoding default-charset="UTF-8" />
    <property name="alternatedocroot_1" value="from=/static/* dir=./docroot/" />
</glassfish-web-app>

Remember that the real path must contain static directory: [...]/glassfish/domains/domain1/docroot/static/

相关阅读:
Top