How to reference an img in p:graphicImage from the resource folder [duplicate]

喜夏-厌秋 提交于 2020-01-24 12:17:21

问题


I have an image in the following path:

resources
\_____img
 \_______sites
  \_______reddit.png

I used this command line to reference it:

<p:graphicImage library="img" name="/sites/reddit.png"/>

but in the development console it says:

GET http://localhost:8080/RES_NOT_FOUND 404 ()

and the image is not rendered.

What's wrong?


回答1:


Kukeltje's suggested url (What is the JSF resource library for and how should it be used?) is definitive resource to resolve this issue.

Based on that URL, I think the resources folder should not be under WEB-INF. It should have a structure as follows assuming that you are using a default maven project layout

src/main/webapp/resources
-------------------------/img
-----------------------------/sites
-----------------------------------/reddit.png
src/main/webapp/WEB-INF
-----------------------/web.xml

Then the following JSF construct should work.

<p:graphicImage library="img" name="sites/reddit.png"/>


来源:https://stackoverflow.com/questions/40771002/how-to-reference-an-img-in-pgraphicimage-from-the-resource-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!