1

Hi I am trying to display image which I have stored in my tomcat's webapps folder

i.e(/webapps/test_Proj/images)

in this way.

<h:graphicImage value="/images/#{backBean.obj.image}" />

When I am trying to see it in Mozilla debug mode, it's showing me error as

'failed to load given url'

it is also showing correct path as

/test_proj/images/sample.png

where my images are stored What I am missing here ? How should I overcome with this problem?

Java
  • 2,451
  • 10
  • 48
  • 85
  • Is your path including the context path? – Alexandre Lavoie May 02 '13 at 08:29
  • Is it really stored in tomcat folder or in your web app ? – Daniel May 02 '13 at 08:32
  • yes I am storing my images to this path"webapp/test_proj/images/" folder. – Java May 02 '13 at 08:38
  • 1
    jsf component h:graphicImage automatically includes context path by itself as told here in ans by @Balusc http://stackoverflow.com/questions/4148555/el-context-path-evaluation-difference-between-outputlink-and-graphicimage – Java May 02 '13 at 09:15
  • Your question is very confusing. Did you store it in Tomcat's `/images` folder or did you store it in webapp's `/images` folder? Note that your own attempt assumes the latter and Vikas' answer assumes the former. Your statement "where my images are stored" assumes the latter, however this should not produce this error at all. – BalusC May 02 '13 at 12:45
  • @Balusc My images are stored in webapps folder path is eg: "/webapps/test_Proj/images/" .that means I have created a folder with name images in my project(test_Proj) – Java May 02 '13 at 13:07
  • Okay, what exactly is the HTTP response on the image request? (status code, headers, body) – BalusC May 02 '13 at 13:08
  • I am using @ViewScoped scope in backing bean and getting 'failed to load given url' in Mozilla firebug mode. – Java May 02 '13 at 16:01
  • I did not ask that. Click the *Net* tab in Firebug and look at the HTTP response of the image. Its status code, headers and body should give clues about the cause. – BalusC May 03 '13 at 12:15

1 Answers1

0

Not sure if this has to be called dirty work or a hack... but it works :)

In server.xml, place the below content.

<Context path="/YourContextName/images" docBase="D:/Servers/Tomcat/images" />

For eg., I have created HelloWorld.war. So for YourContextName I have given the value HelloWorld. I have placed all my images which I want to render under D:/Servers/Tomcat/images. When you start your server, make sure you can access your images by typing below path.

http://localhost:8080/HelloWorld/images/SampleScreenShot.JPG

And finally in your facelets page,

<h:graphicImage value="/images/SampleScreenShot.JPG"></h:graphicImage>

Remember Context path is added automatically. So above code would result in

http://localhost:8080/HelloWorld/images/SampleScreenShot.JPG

Vikas V
  • 3,176
  • 2
  • 37
  • 60
  • Thank you for quick reply, I understood – Java May 02 '13 at 10:58
  • ya.. Under D drive, I have Servers folder which contains Tomcat folder. Under Tomcat folder, I have manually created images folder and have placed those images. – Vikas V May 02 '13 at 11:01
  • Note that it's unnecessary to manually add a `` if the `/images` folder is placed inside `Tomcat/webapps`, there where all your deployments end up. – BalusC May 02 '13 at 12:47