2015-07-20 31 views
1

我使用Struts和hibernate與oracle數據庫並試圖將圖像存儲在數據庫中,並從數據庫檢索圖像並將其顯示在jsp頁面上 我可以設置和獲取圖像,但能夠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,但我無法訪問它,請幫助我..

+0

你說「我可以設置和獲取圖像,但能夠在jsp頁面上顯示圖像。」。 你也許是說「我可以設置和獲取圖像,但無法在jsp頁面上顯示圖像。」 –

+0

yaa我無法在jsp頁面上顯示 –

+0

請參閱'html'生成的代碼,它使用'img'標籤顯示它。 – Satya

回答

-1

我的建議是將數據庫中的圖像路徑存儲在與圖像的物理路徑相同的數據庫中。圖像路徑並將其傳遞給jsp並對其進行迭代。

+0

然後我如何將圖像存儲在特定路徑 –

+0

我只從jsp頁面拍攝圖像 –

+0

假設您的圖像物理路徑是c:\ abc然後在db中將strore圖像路徑設爲c:\ abc \ 1.jpg 。 –

相關問題