我在index.xhtml文件中显示图像时遇到问题。
我希望数据库中的链接指向图像文件,以便<h:graphicImage/>
或<img />
标记可以显示它。目前仅使用localhost。
我已经成功地将一个图像保存到c:\var\webapp\images\中,并将<property name="alternatedocroot1" value="from=/images/* dir=/var/webapp" />
添加到我的glassfish-web.xml中,并使用:
<h:graphicImage value="#{entity.imageLink}" />
<img alt="#{entity.title}" src="#{entity.imageLink}" />
但我从来没有设法显示任何图像!在我的数据库中应该写些什么来显示保存在c:\var\webapp\images\imageExample.jpg中的image_Example.jpg?我的想法是问题出在我的道路上,但我很可能错了。
解决如下问题:
已更改<property name="alternatedocroot1" value="from=/images/* dir=/var/webapp" />
到<property name="alternatedocroot_1" value="from=/images/* dir=c:varwebapp" />
注意斜线。
在我的数据库(MySQL)中,我保存了/images/imageExample.jpg
,然后它将与<h:graphicImage value="#{entity.imageLink}" />
一起显示。
我现在可以访问http://localhost:8080/<MyAppName>/images/imageExample.jpg
上的图像。
如果有疑问,最好将ln打印到服务器日志中,查看您传递给标记的内容,但我认为问题是,当使用反斜杠时,它应该加倍,因为它用于转义字符。