GlassFish 4.1 alternatedocroot, Access static contents

末鹿安然 提交于 2019-12-02 00:34:57

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/

Thanks you'are great my friend. It works for me, in my Glassfish 4.1.1.

I had this code in my glassfish-web.xml, under WEB-INF:

<?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 error-url="">
    <context-root>/GestionProcesos</context-root>
    <class-loader delegate="true"/>
    <jsp-config>
        <property name="keepgenerated" value="true">
              <description>Keep a copy of the generated servlet class' java code.   </description>
        </property>
    </jsp-config>
</glassfish-web-app>

But now my glassfish-web.xml file, I have it like that:

<?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 error-url="">
    <context-root>/GestionProcesos</context-root>
    <class-loader delegate="true"/>
    <property name="alternatedocroot_1" value="from=/Downloads/* dir=/Users/Cristian/" />
</glassfish-web-app>

So, to download a file in my jsp:

<a href="${pageContext.request.contextPath}/Downloads/FileName.pdf" download="FileName.pdf">Download file</a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!