I have to doubts regarding to calling images that are stored in my project:
1-If i have an image stored at MyApp/images/image.gif
How can i tell the component h:graphicImage to find that image? I tried this but it didn't work
<h:graphicImage value="MyApp/images/image.gif"/>
2- I am interested in knowing how to call images that are stored under WEB-INF/images I read somewhere that I need a servlet for that because cannot be accessed directly.
Is t开发者_如何学编程hat true? How can i do that?
Update
This is a print screen of my projectStructure, so you can see where are the files where i need to access.
Here is a summary of the cause of you issue:
- A browser loads each image by sending an HTTP request for the resource.
- Resources that are under the WEB-INF directory can not be directly retrieved via an HTTP request.
You have several options:
- Move the images directory such that it is under the WebContent directory, but is not under the WEB-INf directory. For example, *WebContent/images*
- Intercept requests for images in a servlet or filter, read the file from within the servlet or filter, then return the file. There are 3rd party implementations of this. I like the Spring ResourceServlet class; if nothing else, it will demonstrate this technique (it is open source, so you can just read the code if you like).
精彩评论