我想在/var/映像下显示外部图像文件。为此,我在配置/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>发布于 2015-10-30 09:38:57
<h:graphicImage>不适合用于从外部URL服务图像。它将value解释为上下文相对URL,并自动将webapp的上下文路径添加到给定的value。
换句话说,当webapp被部署到/somecontext的上下文路径时,那么
<h:graphicImage value="/img/test.jpg" />生成
<img src="/somecontext/img/test.jpg" />您应该注意到,通过检查浏览器控制台中img上生成的HTML输出和404错误(在Chrome/Firefox23 23+/IE9+中按F12 )。
只需使用普通的HTML <img>而不是<h:graphicImage>。在你的具体情况下,它不会带来额外的好处。使用JSF组件只会增加不必要的开销。
<img src="/img/test.jpg" />另请参阅:
https://stackoverflow.com/questions/33422416
复制相似问题