, but the proble...">

Dynamically Generated Images Using POST

I need to dynamically load images inside JSP. I tried <img src="servletUrl?p1=x&p2=y"/>, but the problem is the url is too long to send using GET.

Now I am making a POST call. From the servlet, I create a pie chart image based on the parameters that I send. The image is not saved, so I can’t return something like “images / image1.jpg” and set it as src of the image.

So, I return the image as an array of bytes and set the appropriate type of image content.

My question is: as soon as I have image bytes in javascript, how can I display them in the corresponding img tag?

This is my AJAX call:

new Ajax.Request(url, {
        method: 'post',
        parameters: params,
        onComplete: function(request) {
                    alert(request.responseText);      
        }
});
+5
2

, . src dataUrl. byte[] base64, .

new Ajax.Request(url, {
        method: 'post',
        parameters: params,
        onComplete: function(response) {
            var img = new Image();
            img.src = "data:image/png;base64," + response;

            document.body.appendChild(img);
        }
});
+2

:

AJAX <img> <iframe>, POST onload, script. script , iframe, .

0

All Articles