为什么我的图像在jsp中显示默认图标?下面有一张图片

为什么我的图像在jsp中显示默认图标?下面有一张图片,jsp,servlets,web-applications,blob,Jsp,Servlets,Web Applications,Blob,*这是JSP* 你看,有图像显示,但这些图像都是一样的。这些图像不是真正的图像,而是代表损坏图像的图标,就像加载不支持flash的浏览器时一样。当你的浏览器不支持flash时,你看到的就是我说的那个。但它不是一个“f”,而是一个代表损坏图像的图标。所有图像都是从URL加载的 getImageDetails.jsp?your_id=12 所以这个URL不是指向servlet,而是指向JSP。即使它指向您的servlet,servlet也希望在参数product\u code中找到要加载的图像ID

*这是JSP*


你看,有图像显示,但这些图像都是一样的。这些图像不是真正的图像,而是代表损坏图像的图标,就像加载不支持flash的浏览器时一样。当你的浏览器不支持flash时,你看到的就是我说的那个。但它不是一个“f”,而是一个代表损坏图像的图标。

所有图像都是从URL加载的

getImageDetails.jsp?your_id=12
所以这个URL不是指向servlet,而是指向JSP。即使它指向您的servlet,servlet也希望在参数
product\u code
中找到要加载的图像ID,但您正在传递参数
您的\u ID

    response.setContentType("image/jpeg");
    PrintWriter out = response.getWriter();

    int img_id = Integer.parseInt(request.getParameter("product_code"));
    DBConnectionImp db = new DBConnectionImp();
    Connection con = db.getConnection();
            ResultSet rs = null;
    PreparedStatement pstmt = null;
    OutputStream oImage;
    try {
        pstmt = con.prepareStatement("SELECT Warehouse_Stock.photo from Warehouse_Stock");
        pstmt.setInt(1, img_id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            //byte barray[] = rs.getBytes(1);
            //byte barray[] = rs.getBytes(1);
            //response.setContentType("image/jpeg");
            ////oImage = response.getOutputStream();
            //oImage.write(barray);
           // oImage.flush();
            //oImage.close();

            Blob blob = rs.getBlob(1);

            //response.setContentType("image/jpeg");
            oImage = response.getOutputStream();
            oImage.write(blob.getBytes(1, (int) blob.length()));
            oImage.flush();
            oImage.close();



        }
    } catch (Exception ex) {
        //ex.printStackTrace();
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception ex) {
            // ex.printStackTrace();
        }
    }
getImageDetails.jsp?your_id=12