3.2.0

how to push an automatically refreshed BufferedImage generated in a servlet into the browser?

Hi
I am involved in an application that generates a BufferedImage .A servlet is doing the process.i want to refresh the image every 1 minute.for this i am using some infinite while loop and suspending the servlet every i minute.i have to push this refreshed image into the browser.this has to be done with javascript.how is this possible? if anyone has any idea please tell me.Thanks in Advance
Regards
Anu
July 8,
maybe u can try this:

<script>
var imageRequest = new AW.HTTP.Request;
imageRequest.setUrl('/servletImage/getImage');
imageRequest.setAsync(true);
imageRequest.response = function(xml) {
     // get the src of new image generated
     // like: /images/image_0048448464849849.gif
     var resolver = xml.createNSResolver( xml.ownerDocument == null ? xml.documentElement : xml.ownerDocument.documentElement));
      var value = xml.evaluate('//root//imageSRC', xml, resolver, XPathResult.ANY_TYPE, null).stringValue;
    /*
      example XML
        <root>
           <imageSRC>images/image_0048448464849849.gif</imageSRC>
        </root>
    */
     // create new image
     var im = new Image();
     im.src = value;
     // set new image
     document.getElementById('myImage').src = im.src;
     // done
}
imageRequest.request();
</script>
<body>
<img src='/images/blank.jpg' id='myImage' name='myImage'>
</body>

U can't return the bytes in browsser, because u need SRC for image, u can't do nothing with bytes.
cya.
Paulo Cesar Silva Reis (PC from Brazil).
July 8,
or maybe u can write in response setting the content type, like:

response.setContentType("image/gif");
response.getPrinter().write(IMAGE_BYTES);
response.flush();

And set the IMG SRC to servlet, to refresh u can re-set the src like:
document.getElementById("image").src =  document.getElementById("image").src+"?"+new Date().getTime();

hope this help.
Paulo Cesar Silva Reis (PC from Brazil).
July 8,

This topic is archived.

See also:


Back to support forum