Friday, June 10, 2011

HOW TO USE IMAGES IN A JEE6 PROJECT?(Most common approaches)

<h:graphicImage id="img" value="/images/download.gif" alt="The image could not be found."/> 

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.If you dont want to write your own servlet for this, Im sure with a bit of search you can find a servlet that suits your needs in google.


Share with your friends