[英]How to show the server path image to PrimeFaces p:graphicImage?
When I retreive server path and show into the p:graphicImage
tag, then images are not displayed. 当我检索服务器路径并显示到p:graphicImage
标记时,不显示图像。 Images are loaded into outside the webbapp folder. 图像被加载到webbapp文件夹之外。 Server path of the images are like this \\\\qbsserver\\Test Folder\\test\\car.jpg
. 图像的服务器路径类似于\\\\qbsserver\\Test Folder\\test\\car.jpg
。
<p:graphicImage value="\\qbsserver\Test Folder\test\\#{image.imageName}" />
How can I make them to display? 如何让它们显示? I am using PrimeFaces 3.0 and JSF 2.0 in Eclipse IDE. 我在Eclipse IDE中使用PrimeFaces 3.0和JSF 2.0。
You're making a conceptual mistake. 你犯了一个概念上的错误。 It's not the server who includes and sends the image along with the generated HTML output somehow. 服务器不是以某种方式包含和发送图像以及生成的HTML输出。 It's the webbrowser who downloads the image by its URL as specified in the <img src>
when it encounters an <img>
tag in the HTML. Web浏览器在HTML中遇到<img>
标记时,按照<img src>
指定的URL下载图像。
So it has really to be a normal URL, exactly the one as the enduser would enter in the webbrowser's address bar, not a server specific local disk file system path. 所以它确实是一个普通的URL,正是最终用户在webbrowser的地址栏中输入的URL,而不是服务器特定的本地磁盘文件系统路径。 The enduser using the webbrowser really doesn't have that image on exactly that path on its local disk file system. 使用webbrowser的最终用户实际上没有在其本地磁盘文件系统上的该路径上具有该映像。
Easiest would be to add the folder as a "virtual context" of the servletcontainer which you're using. 最简单的方法是将文件夹添加为您正在使用的servlet容器的“虚拟上下文”。 It's unclear which one you're using. 目前还不清楚你正在使用哪一个。 In Tomcat it's a matter of adding a new <Context>
to the server.xml
在Tomcat中,需要在server.xml
中添加一个新的<Context>
<Context docBase="/path/to/images" path="/images" />
and in Glassfish it's a matter of adding an alternatedocroot
to the glassfish-web.xml
而在Glassfish中,可以在glassfish-web.xml
中添加alternatedocroot
<property name="alternatedocroot_1" value="from=/images/* dir=/path/to" />
Refer the documentation of the servletcontainer for details. 有关详细信息,请参阅servletcontainer的文档。 Ultimately they should be accessible by a normal URL so that you can just use for example: 最终,它们应该可以通过普通URL访问,以便您可以使用例如:
<p:graphicImage value="/images/#{image.imageName}" />
Other ways involve using PrimeFaces StreamedContent
API or homegrowing a servlet. 其他方法涉及使用PrimeFaces StreamedContent
API或homegrowing servlet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.