How to retrieve and display images from a database in a JSP page?

前端 未结 5 1917
渐次进展
渐次进展 2020-11-21 04:37

How can I retrieve and display images from a database in a JSP page?

5条回答
  •  情歌与酒
    2020-11-21 05:15

    Try to flush and close the output stream if it does not display. Blob image = rs.getBlob(ImageColName); InputStream in = image.getBinaryStream(); // Output the blob to the HttpServletResponse response.setContentType("image/jpeg"); BufferedOutputStream o = new BufferedOutputStream(response.getOutputStream());

        byte by[] = new byte[32768];
        int index = in.read(by, 0, 32768);
        while (index != -1) {
            o.write(by, 0, index);
            index = in.read(by, 0, 32768);
        }
        o.flush();
        o.close();
    

提交回复
热议问题