开发者

How to access image resources in JEE6 project?

开发者 https://www.devze.com 2023-02-21 05:12 出处:网络
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

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.

How to access image resources in JEE6 project?


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:

  1. Move the images directory such that it is under the WebContent directory, but is not under the WEB-INf directory. For example, *WebContent/images*
  2. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消