Wednesday, March 21, 2007

writing the image as stream from servlets

You can use the following code to push the image as stream from the server (What if you dont have the image as a file? What if you create an image stream rather than reading an image file?)



HttpServletRequest req = (HttpServletRequest)request;

HttpServletResponse res = (HttpServletResponse)response;



byte[] ba = getImageBytes(); //implement a method to read the image bytes



ServletOutputStream sos = res.getOutputStream();

res.setContentType("image/jpeg"); //give the corresponding image type.

res.setContentLength(ba.length);

sos.write(ba);



This way you can write any no of images as stream to your web page.



/>



powered by performancing firefox

No comments: