如何从 WildFly 上的战争之外提供静态资源 [英] How can I serve static resources from outside a war on WildFly

查看:32
本文介绍了如何从 WildFly 上的战争之外提供静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I may be wrong, but to my understanding, the following must be possible in WildFly:

必须可以在我的 JSF 视图(即 xhtml 文件)中放置一个链接到 WildFly 服务器上已有的资源(pdf、图像、其他 xhtml 文件).

It must be possible to put a link into my JSF views (i. e. the xhtml files) to a resource (pdf, image, other xhtml file) that is already on the WildFly server.

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

I can do the same thing in php and an apache server.

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

Where would I need to put those resources and how can I access them from my views? E. g. put a link in the view to a pdf file that opens the pdf file in a new tab.

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

Thanks a lot for tips and hints!!

编辑

独立文件.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>

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

When I click on this, I get the directory listing, as you said.

但是如何才能显示content指向的目录中的index.xhtml??这真的是我想要的.

But how can I make it so that the index.xhtml in the directory that content points to is displayed?? That's really what I want.

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

content points to ${jboss.home.dir}/standalone/data/unzipped and in unzipped there is an index.xhtml as well as another folder with more .xhtml files.

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

In the index.xhtml there are relative links to the .xhmtl files in the folder:

<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 文件.

I want to display the index.xhtml file in unzipped and from there navigate to the other .xhtml files.

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

Something like that must be possible, must not it??

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

Or how else would you write an application where a user can upload html files to a Java ee server and then see those files displayed?

推荐答案

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

You may not want to deploy all your static content with your application. These may be images, PDF documents, or other types of files. You should configure Undertow in order to solve this problem. Below example shows you how to do this by configuring Undertow subsytem.

<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,则请求将被重定向为正确显示的文件.

With this additional configuration, any request for resources to www.sampledomain.com/contextroot/img will be redirected to the filesystem on your hard disk. If you mark "directory-listing" attribute as false, then requests will be redirected as a properly displayed file.

这篇关于如何从 WildFly 上的战争之外提供静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆