How to show images in div that stored in db
I decided to store uploaded to servlet pictures in DB. But how to show them in browser (in particular div with css image-backgr开发者_高级运维ound style) without page reload?
In details: I have an full-AJAX web client that works with java servlet.
Thanks.
- Create a servlet that accepts a name / id uniquely identifying the picture as a GET parameter
- Let the servlet load the picture from DB (as byte array or better - as stream)
- Stream the picture using
response.getOutputStream()
- Don't forget to set the content-type to
image/png
orimage/jpeg
- Refer to the image in the css with
url: imageServlet?id=13214
精彩评论