【问题标题】:How can I serve static resources from outside a war on WildFly如何在 WildFly 战争之外提供静态资源
【发布时间】:2016-03-29 07:43:46
【问题描述】:

我可能错了,但据我了解,WildFly 中必须有以下可能:

必须可以将链接放入我的 JSF 视图(即 xhtml 文件)中,指向已经在 WildFly 服务器上的资源(pdf、图像、其他 xhtml 文件)。

我可以在 php 和 apache 服务器中做同样的事情。

我需要将这些资源放在哪里?如何从我的视图中访问它们?例如。在视图中放置一个指向 pdf 文件的链接,该文件会在新选项卡中打开 pdf 文件。

非常感谢您的提示和提示!

编辑

独立的.xml

<server name="default-server">
    <http-listener name="default" socket-binding="http" max-post-size="974247881"/>
    <host name="default-host" alias="localhost">
        <location name="/" handler="welcome-content"/>
        <location name="/content" handler="ContentDir"/>
        <filter-ref name="server-header"/>
        <filter-ref name="x-powered-by-header"/>
    </host>
</server>
<servlet-container name="default">
    <jsp-config/>
    <websockets/>
</servlet-container>
<handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    <file name="ContentDir" path="${jboss.home.dir}/standalone/data/unzipped" directory-listing="true"/> 
</handlers>

JSF 视图中的链接

<h:outputLink value="http://localhost:8181/content">KLICK</h:outputLink>

当我点击这个时,我得到了目录列表,正如你所说的。

但是如何才能让content指向的目录中的index.xhtml显示出来呢?这正是我想要的。

content 指向${jboss.home.dir}/standalone/data/unzipped,解压后有一个index.xhtml 以及另一个包含更多.xhtml 文件的文件夹。

index.xhtml 中有指向文件夹中.xhmtl 文件的相对链接:

<ul>
    <li><a href="t/rt.html">hg</a></li>
    <li><a href="t/tert.html">jghj</a></li>
    <li><a href="t/gf.html">jghj</a></li>
    <li><a href="t/hg.html">jghj</a></li>
    <li><a href="t/hgfh.html">jghj</a></li>
    <li><a href="t/hfgh.html">jhgj</a></li>
    <li><a href="t/hfgh.html">jhgj</a></li>
    <li><a href="t/hg.html">jghj</a></li>
    <li><a href="t/hghh.html">jghj</a></li>
</ul>

我想在unzipped 中显示index.xhtml 文件,然后从那里导航到其他.xhtml 文件。

这样的事情一定是可能的,不是吗??

或者你会如何编写一个应用程序,用户可以将 html 文件上传到 Java ee 服务器,然后查看这些文件的显示?

【问题讨论】:

    标签: wildfly wildfly-8 undertow


    【解决方案1】:

    您可能不想将所有静态内容部署到您的应用程序中。这些可能是图像、PDF 文档或其他类型的文件。您应该配置 Undertow 以解决此问题。下面的示例向您展示了如何通过配置 Undertow 子系统来做到这一点。

    <server name="default-server">
        <http-listener name="default" socket-binding="http"/>
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <location name="/img" handler="images"/>
        </host>
    </server>
    <handlers>
        <file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="false"/>
        <file name="images" path="/var/images" directory-listing="true"/>
    </handlers>
    

    使用此附加配置,对www.sampledomain.com/contextroot/img 的任何资源请求都将被重定向到硬盘上的文件系统。如果将“目录列表”属性标记为 false,则请求将被重定向为正确显示的文件。

    【讨论】:

    • 实际上,我希望用户能够自己更新 zip 文件中的静态内容,然后访问它。如果我将我的静态内容放在我的应用程序中,我知道该怎么做——我只是把它们放在我的 webapp 文件夹中。因此,根据您的解决方案,我可以将链接放入指向 www.sampledomain.com/contextroot/somefile.xhtml 的视图文件(.xhtml)中?在那个 .xhtml 文件中,我可以链接到其他资源?
    • 您的问题或其标题未包含任何有关更新过程的陈述,因此我的回答对于该问题是正确的。我认为您应该编辑您的问题以防止错误理解。
    • 是的,您的评论是正确的。您的 .xhtml 文件可以指向任何 pdf、图像或其他 xhtml 文件,但指向的文件将显示为硬盘上的文件系统。
    • 是的,很抱歉!感谢您的回答!
    • 我尝试了您的回答并编辑了我的问题。如果您能再看看或分享您的想法和想法,我会非常酷!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    相关资源
    最近更新 更多