简体   繁体   English

如何将服务器路径图像显示到PrimeFaces p:graphicImage?

[英]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。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GlassFish alternatedocroot路径应该如何在h:graphicImage中显示图像? - How should GlassFish alternatedocroot path be to display an image in h:graphicImage? <p:galleria><p:graphicImage>没有显示所需的图像 - <p:galleria><p:graphicImage> doesn't show the desired images 使用 p:graphicImage 和 StreamedContent 显示来自数据库或远程源的动态图像 - Display dynamic image from database or remote source with p:graphicImage and StreamedContent 影像不必要地显示在 <p:graphicImage> 事件虽然没有提供资源目录中的图像名称 - Image is unnecessarily displayed on <p:graphicImage> event though the image name from the resources directory is not given 使用多个 p:graphicImage 在没有多个 HTTP 请求的情况下多次显示相同的图像 - Displaying the same image several times with multiple p:graphicImage without multiple HTTP requests 在PrimeFaces p:datatable中禁用图像提交按钮 - Disable image submit button in PrimeFaces p:datatable 显示多个 <p:graphicImage> 在一页上 - Display multiple <p:graphicImage> on one page 如何将图像添加到primefaces菜单栏? - How to add an image to a primefaces menubar? 如何从服务器驱动器获取图像路径 - how to get image path from server drive 如何获取图像路径作为字符串并将其保存到服务器 - how to get image path as a string and save it to a server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM