Search code examples
htmlcssdeploymentweb-applicationspayara

Can't access an image from inside a folder when I deploy the web application


Making a simple Web Application using NetBeans and trying to use an image but wherever I put the image, it is inaccessible, except if I have in the same directory as the my index.xhtml.

Saved "myimage.jpg" inside webapp folder (along with index.xhtml), and also inside a resources folder and then inside an image folder.

Showing:

<img src="myimage.jpg"/>

Not showing:

<img src="resources/myimage.jpg"/>
<img src="resources/images/myimage.jpg"/>

When I deploy the application if I try typing manually at the browser:

(url of the payara server)*/title/myimage.jpg

I can see the image but if I try:

(url of the payara server)*/title/resources/myimage.jpg
(url of the payara server)*/title/resources/images/myimage.jpg

I get an "HTTP Status 404 - Not Found" error.

(I also tried a lot of different paths to find it like /, ./, ../, //, but nothing seems to work.)


Solution

  • You should place your static file inside src/main/webapp/resources and your .xhtml in src/main/webapp/WEB-INF and your JSF file can then request your file like the following:

    <h:graphicImage name="myimage.jpg" id="image"/>