How to serve static web pages from a JSF application using Glassfish

感情迁移 提交于 2019-12-01 08:37:21

问题


I have a JSF 2.0 application running under Glassfish 3.1.1 and I need to serve static web pages that are physically located apart from my application root that is created when my WAR file is deployed. I've found various references (like this one and this one) to defining an alternate docroot using a tag such as

<property name="alternatedocroot_1" value="from=/myimages/* dir=/images"/>

added to sun-web.xml (which I would presume means glassfish-web.xml in Glassfish 3.1.1). I can't seem to get it to work, however. In my case, I think the problem is that glassfish-web.xml simply isn't defining enough context for the alternate docroot to have any meaning:

<?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="">
  <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>
  <property name="alternatedocroot_1" value="from=/myimages/* dir=/images"/>
</glassfish-web-app>

The meat of my application definition seems to be much more in web.xml than glassfish-web.xml. Do I perhaps need to put something there instead to reference the alternate docroot?


回答1:


This exact configuration requires a /images/myimages folder relative to the absolute root of the same disk as where the JVM of the webserver is running in. A file foo.png in that folder is then available by http://localhost:8080/contextname/myimages/foo.png.

A common confusion around this setting is that the from attribute is been interpreted as alone the context path in URL and not as an actual subfolder in the dir location. But this is thus not true.

If you're running Glassfish on a Windows environment then you need to specify the disk letter in the dir as well like so dir=C:/images.



来源:https://stackoverflow.com/questions/10708379/how-to-serve-static-web-pages-from-a-jsf-application-using-glassfish

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!