I have sent image from j2me to servlet in base64 format,decoded that base64 format to byte array again. Now i have have byte array of an image (something like this "[B@ea0ef881"). Now i want to create image out of this array in my servlet and display it to user in JSP. Plz Help Thanks in advance
1 Answer
Use FileOutputStream to create the new image file from the bytearray.
something like..out.write(bytearray);
and then while showing it to a user via jsp use..
response.setContentType("image/gif");
your code would look something like this...
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
2 Comments
Dhiraj Valechha
@shashankkande can you help me more with servlet code..i have stored this byte array as BLOB in mysql now so how to retrieve that and store create image from that binary data
Shashank Kadne
Connection con = DriverManager.getConnection("jdbc:mysql:///test","root","root"); PreparedStatement ps = con.prepareStatement("select image from img"); ResultSet rs = ps.executeQuery(); FileOutputStream fs = new FileOutputStream(new File("C:\\Users\\123\\Desktop\\test.gif")); while(rs.next()) { InputStream is = rs.getBinaryStream(1); response.reset(); response.setContentType("image/gif"); int c; while((c=is.read())!=-1) { fs.write(c); fs.flush(); } }