I've found very nice solution of retrieving images from db/blob thanks to How to retrieve and display images from a database in a JSP page?
But this is solution that uses JDBC connection on every image request.
I'm using Spring 3 annotations and Hibernate 3.
I tried to do similar thing by my 'imageService', which is autowired by annotation in ImageServlet class, but I got nullPointerException, which means that may imageService is not set by Dependency Injection.
Is there any way how to solve that? I don't like to make single jdbc connection on image request.
I hope you are storing the image in the table as a BLOB type(If not try to do so, as this is the best practice). Lets assume you have a
Person
class with the animage
of the person stored in the DB. If you want to map this, just add a property in your person POJO that holds the image.When you display it, convert it to a
byte[]
and show.You can see the below examples to know more about it.
As you can see there are multiple ways to do this. Choose the one appropriate for you.