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

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

问题描述

当我检索服务器路径并显示到 p:graphicImage 标记中时,图像不会显示.图像加载到 webbapp 文件夹之外.图片的服务器路径如下\qbsserverTest Folder estcar.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 \qbsserverTest Folder estcar.jpg.

<p:graphicImage value="\qbsserverTest Folder	est\#{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 输出的不是服务器.当浏览器遇到 HTML 中的 标记时,它会通过 中指定的 URL 下载图像.

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,正是最终用户在 web 浏览器的地址栏中输入的 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. The enduser using the webbrowser really doesn't have that image on exactly that path on its local disk file system.

最简单的方法是将文件夹添加为虚拟上下文".您正在使用的 servletcontainer.不清楚你用的是哪一种.在 Tomcat 中,只需将新的 添加到 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}" />

其他方法包括使用 PrimeFacesStreamedContent API 或自建一个 servlet.

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

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

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