:: Forum >> Version 2 >>

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
Saturday, July 8, 2006
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.createNSResolverxml.ownerDocument == null ? xml.documentElement xml.ownerDocument.documentElement));
      var 
value xml.evaluate('//root//imageSRC'xmlresolverXPathResult.ANY_TYPEnull).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).
Saturday, July 8, 2006
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).
Saturday, July 8, 2006



This topic is archived.

Back to support forum

Forum search