2012-01-21 36 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。 –