jsf - 在 JSF 中显示 Wildfly 之外的外部图像

标签 jsf jboss7.x wildfly

我想显示/var/images下的外部图像文件。为此,我在configuration/standalone.xml 中为图像文件夹添加了另一个图像处理程序“img”子系统,如下所示。现在我可以通过 http://localhost:8080/img/test.jpg 浏览该文件夹。

<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"/>**
                        <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="images" path="/var/images" directory-listing="true"/>**
            </handlers>

但是,我无法在下面的 JSF 代码中正确显示它。图像不会显示在浏览器的 html 页面中。知道缺少什么或有什么问题吗?谢谢。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:p="http://primefaces.org/ui" 
    >

<ui:composition template="template.xhtml">
    <ui:define name="content">
        <h:messages />

        <h:form id="myform">
            <h:panelGrid columns="5">

                <h:graphicImage value="/img/test.jpg" />
                ...
            </h:panelGrid>
        </h:form>
        <br />


    </ui:define>
</ui:composition>
</html>

最佳答案

<h:graphicImage>不适合从外部 URL 提供图像。它解释了 value作为上下文相关 URL 并自动将 Web 应用程序的上下文路径添加到给定的 value .

换句话说,当webapp部署到/somecontext的上下文路径时,那么

<h:graphicImage value="/img/test.jpg" />

生成

<img src="/somecontext/img/test.jpg" />

您应该已经注意到,通过在浏览器控制台中检查生成的 HTML 输出和 img src 上的 404 错误(在 Chrome/Firefox23+/IE9+ 中按 F12)。

只需使用纯 HTML <img>而不是<h:graphicImage> 。对于您的具体情况,它没有任何额外的好处。使用 JSF 组件只会增加不必要的开销。

<img src="/img/test.jpg" />

另请参阅:

关于jsf - 在 JSF 中显示 Wildfly 之外的外部图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33422416/

相关文章:

JSF 临时变量

java - 如何在 Wildfly 中配置 Jackson?

javascript - 在 Wildfly 10 上部署 Vue.js

jboss - 在域模式下在从属之间共享属性文件 Wildfly10

java - jboss无法添加mysql驱动

java - 如何将 Hibernate 从 MySQL 迁移到 SQL Server?

css - 如何使用 JSF 嵌入 CSS 背景图像链接?

java - 更大范围内需要 JSF 2.0 URL 参数

jsf - 为什么 JSF 会点击 xhtml 页面 3 次

jboss7.x - RESTeasy、EJB 和@Context 对象注入(inject)