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

时间:2015-07-20 05:13:27

标签: java hibernate jsp struts2

我正在使用Struts和hibernate与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,但我无法访问它,请帮助我..

1 个答案:

答案 0 :(得分:-1)

我的建议是将您的图像路径存储在数据库中,该路径与图像的物理路径相同。然后将图像路径列表传递给jsp并迭代它。

相关问题