我正在使用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
,但我无法访问它,请帮助我..
最佳答案
我的建议是将图像路径存储在数据库中,该数据库与图像的物理路径相同。之后创建图像路径列表并将其传递给jsp并迭代它。
关于java - 如何在jsp页面上动态显示数据库中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31509213/