繁体   English   中英

如何从jsp页面上的数据库动态显示图像

[英]How to display an image dynamically from database on the jsp page

我正在使用Struts并使用oracle数据库进行休眠,并尝试将图像存储在数据库中并从数据库中检索图像,并将其显示在jsp页面上,但是我能够设置并获取图像,但能够在jsp页面上显示图像。 ..

使用此代码...

public String getImage() throws UnsupportedEncodingException {
    String simage=new String(image, "UTF-8");
    System.out.println(simage);
    try {
        FileOutputStream fw = new FileOutputStream("ItemImages/"+simage);
        fw.write(image);
    } catch (FileNotFoundException ex) {
        System.out.println(ex);
//Logger.getLogger(Items.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        System.out.println(ex);
    } finally
    {
        return simage;
    }

}

public void setImage(String image) {    
    byte [] bimage = image.getBytes();
    this.image = bimage;
}

jsp代码:-

<ss:iterator value="#productList.products" var="item">
<img src="ItemImages/<ss:property value="#item.image" />"></img>
</ss:iterator>

我在网页中创建了一个文件夹ItemImages ,但我无法访问它,请帮助我。

我的建议是将您的图像路径存储在与image的物理路径相同的数据库中。在此之后,列出图像路径并将其传递给jsp并对其进行迭代。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM