Well, you can have your image call a
servlet or submit a form (if the image is within form tags) which will call a servlet. Let your servlet use the parameter sent in to call some business logic which does the database access, this will return the results to your servlet/controller, which can then forward it to the appropriate JSP for display. This may require a little bit of reading and redisigning on your part, but it's the most appropriatre way to achieve what you described. Searching and reading up on the MVC
pattern will definitely help.