2012-01-21 37 views
1

我已經將圖像從j2me發送到基於64位格式的servlet,並再次將base64格式解碼爲字節數組。現在我有一個圖像的字節數組(像這樣的「[B @ ea0ef881」)。現在我想從我的servlet中的數組中創建圖像,並在JSP中將其顯示給用戶。 Plz幫助 在此先感謝從servlet中的字節數組創建圖像

回答

1

使用FileOutputStream從字節數組創建新映像文件。

類似.. out.write(bytearray);

,然後同時顯示經由JSP使用用戶..

response.setContentType( 「圖像/ GIF」);

您的代碼會是這個樣子......

response.setContentType("image/gif"); 
     OutputStream o = response.getOutputStream(); 
     o.write(imgData); 
     o.flush(); 
     o.close(); 
+0

@shashankkande你能幫助我更與code..i都存放在這個字節數組作爲BLOB在MySQL的servlet現在這麼如何檢索和存儲從該二進制數據創建映像 –

+0

Connection con = DriverManager.getConnection(「jdbc:mysql:/// test」,「root」,「root」); \t PreparedStatement ps = con.prepareStatement(「select image from img」); \t ResultSet rs = ps.executeQuery(); \t FileOutputStream fs = new FileOutputStream(new File(「C:\\ Users \\ 123 \\ Desktop \\ test.gif」)); \t而(rs.next()) \t { \t \t InputStream爲= rs.getBinaryStream(1); \t \t response.reset(); \t \t response.setContentType(「image/gif」); \t \t int c; \t \t而((C = is.read())= - 1!) \t \t { \t \t \t fs.write(C); \t \t \t fs.flush(); \t \t \t \t } \t \t \t \t \t \t \t } –

+0

我使用上述代碼從MySQL檢索BLOB。 –