如何将服务器路径图像显示到PrimeFaces p:graphicImage? [英] How to show the server path image to PrimeFaces p:graphicImage?

查看:187
本文介绍了如何将服务器路径图像显示到PrimeFaces p:graphicImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检索服务器路径并显示到 p:graphicImage 标记时,则不显示图像。图像被加载到webbapp文件夹之外。图像的服务器路径是这样的 \\qbsserver\Test Folder\test\car.jpg

When I retreive server path and show into the p:graphicImage tag, then images are not displayed. Images are loaded into outside the webbapp folder. Server path of the images are like this \\qbsserver\Test Folder\test\car.jpg.

<p:graphicImage value="\\qbsserver\Test Folder\test\\#{image.imageName}" />

如何让它们显示?我在Eclipse IDE中使用PrimeFaces 3.0和JSF 2.0。

How can I make them to display? I am using PrimeFaces 3.0 and JSF 2.0 in Eclipse IDE.

推荐答案

你犯了一个概念上的错误。服务器不是以某种方式包含和发送图像以及生成的HTML输出。 Web浏览器在遇到< img> < img src> 中指定的URL下载图像HTML中的$ c>标记。

You're making a conceptual mistake. It's not the server who includes and sends the image along with the generated HTML output somehow. 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.

所以它确实是一个普通的URL,正是最终用户在webbrowser的地址栏中输入的URL,而不是服务器特定的本地磁盘文件系统路径。使用webbrowser的最终用户在其本地磁盘文件系统上的路径上确实没有该映像。

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. The enduser using the webbrowser really doesn't have that image on exactly that path on its local disk file system.

最简单的方法是将文件夹添加为虚拟上下文 你正在使用的servletcontainer。目前还不清楚你正在使用哪一个。在Tomcat中,需要将新的< Context> 添加到 server.xml

Easiest would be to add the folder as a "virtual context" of the servletcontainer which you're using. It's unclear which one you're using. In Tomcat it's a matter of adding a new <Context> to the server.xml

<Context docBase="/path/to/images" path="/images" />

在Glassfish中添加 alternatedocroot glassfish-web.xml

and in Glassfish it's a matter of adding an alternatedocroot to the glassfish-web.xml

<property name="alternatedocroot_1" value="from=/images/* dir=/path/to" />

有关详细信息,请参阅servletcontainer的文档。最终它们应该可以通过普通URL访问,以便您可以使用例如:

Refer the documentation of the servletcontainer for details. Ultimately they should be accessible by a normal URL so that you can just use for example:

<p:graphicImage value="/images/#{image.imageName}" />

其他方式涉及使用 PrimeFaces StreamedContent API 或者生成一个servlet。

Other ways involve using PrimeFaces StreamedContent API or homegrowing a servlet.

  • Simplest way to serve static data from outside the application server in a Java web application

这篇关于如何将服务器路径图像显示到PrimeFaces p:graphicImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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