0

I have a class with (amongst others) the field picture which is retreived from the database:

public class Person {
  String name;
  Blob picture;
}

So then I haven a controller where I add the person object to the model

@RequestMapping(value = "/online", method = RequestMethod.GET)
public String getCurrentUser(Model model) {
  Person person = getMyPerson()
  model.addAttribute("person", person);
  return "online";
}

And finally I have a .jsp page to display the user:

<html>
  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   ..some tags

   Persons name: ${person.name}
   Persons picture: ?your_answer_here? 
</html>

So the question (obviously) is how do I display the blob field as an image? I have tried and failed with . I really don't want to perform a new query to the database, I just want to display the image I already have ..

1 Answer 1

2

HTTP does not allow this directly. Each image needs to be a separate request to a separate URL. So you will need a controller/servlet that accepts the user id as parameter and writes the blob to the response stream (and sets the Content-Type header appropriately - image/jpeg, image/png, etc)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Implemented a new controller for outputting the image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.