Hi everyone,
I want to display an image **AND** a String using Spring MVC 3.
Both are instance variables of a POJO that I retreive from the database using Hibernate.
I want to display the image on the .jsp page using Spring MVC 3 AND display the String next to it.Code:@Entity @Table(name = "document") public class Document { //id @Column(name = "name") private String name; // the String @Basic(fetch = FetchType.LAZY) @Column(name="content") private byte [] image; //getters setters
Currently I can display ONLY the picture by streaming it and printing the String to the console but it is not what I want. (Of course I can display the String, but if I display the String, then I am not able to display the image.) I want to display both, on the same page, next to eachother.
I was googling for a couple of hours and found very little..I do not want to beleive that there isn't any clever solution to acheive this.Code:@RequestMapping(value = "/displayDocument", method = RequestMethod.POST) public void displayDocument(@RequestParam("documentId") String documentId, HttpServletResponse response) { Document doc = documentService.get(Long.valueOf(documentId)); System.out.println(doc.getName()); if (doc.getImage() != null) { response.setContentType("image/jpg"); try { response.getOutputStream().write(doc.getImage()); response.getOutputStream().flush(); response.getOutputStream().close(); } catch (IOException e) { e.printStackTrace(); } } }


Reply With Quote
