views:

93

answers:

2

I want to serve an image saved as a blob in a MySQL Database through hibernate3 in a JSF application. My intention is that /myapp/image/get.faces?id=x will serve the image saved in the database with id x. How to achieve this?

+2  A: 

My intention is that /myapp/image/get.faces?id=x will serve the image saved in the database with id x.

  • Map this URL to a servlet.
  • From the servlet, retrieve an Entity holding a byte[] (mapped as @Lob ) by id.
  • Stream the image to the HttpServletResponse

The fellow BalusC wrote a nice post about such an image servlet on his blog. If you have troubles with the Hibernate part, please elaborate.

Pascal Thivent
[OT] Wow, Pascal, is stack overflow your fulltime job? :)
Ondra Žižka
A: 

I think RichFaces has some component for this - like it has for almost anything. But I'd recommend the servlet way, see the other answer.

Plus, be sure to put some static content cache in front of your JSF app - pulling it from the DB every time is NOT a good idea.

Ondra Žižka