Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value = "/imageDisplay", method = RequestMethod.GET)
- public void showImage(@RequestParam("id") Integer docId, HttpServletResponse response, HttpServletRequest request)
- throws ServletException, IOException, SQLException {
- Document doc = documentDao.get(docId);
- try {
- response.setHeader("Content-Disposition", "inline;filename="" + doc.getFilename() + """);
- OutputStream out = response.getOutputStream();
- response.setContentType(doc.getContentType());
- IOUtils.copy(doc.getContent().getBinaryStream(), out);
- // response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
- int blobLength = (int) doc.getContent().length();
- byte[] blobAsBytes = doc.getContent().getBytes(1, blobLength);
- System.out.println(doc.getFilename());
- response.getOutputStream().write(blobAsBytes);
- // response.getOutputStream().close();}
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- Test1 : <img src="${pageContext.request.contextPath}/imageDisplay?id=3.html"/>
- Test2 : <img src="/Spring3HibernateIntegration/imageDisplay?id=3.html"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement