Hi everybody,
I've a little problem: I wrote an application that uploads an image in a MySQL blob. It worksd fine. But I cannot retreive and display it ... I show you what I've done :
Controller:
Then, to display it I simply wrote this:Code:@RequestMapping("show") public ModelAndView show(HttpServletRequest req) { if (logger.isDebugEnabled()) { logger.debug("Display image with id " + req.getParameter("id")); } ModelAndView mav = null; if (req.getParameter("id") == null || req.getParameter("id").length() == 0) { return null; } else { try { Integer id = Integer.parseInt(req.getParameter("id")); WebPicture wp = webPictureDao.get(id); mav = new ModelAndView("showPicture"); if (logger.isDebugEnabled()) { logger.debug("serving data : " + wp.getData()); } OutputStream os = new ByteArrayOutputStream(); // wp.getData() = byte[] os.write(wp.getData()); mav.addObject("data", os); } catch (NumberFormatException ex) { return null; } catch (Exception e) { logger.warn("Unable to fetch picture with id " + req.getParameter("id"), e); } } return mav; }
But when I visit the page to display the image, that just displays the url I entered (I think this is because firefox write a complete html page with an img tag in the body, and the url as alt attribute)<%@ page language="java" contentType="image/jpeg" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:out value="${data}" />
Any idea of what's wrong?
thanks!


Reply With Quote
