javainternet-explorerservlets

Why Uploaded Image not being displayed in IE?


I am using simple HTML page for upload and post image to a servlet, then I convert image in byte[] and save it in session using doPost() method:

    response.setContentType("text/html");
    items = upload.parseRequest(request);
    byte[] byteArray = item.get();
    request.getSession().setAttribute("image1", byteArray);

    out.println("<html>");
    out.println("<body onload='javascript:callParent()'>File uploaded successfully.");
    out.println("<img src='/ImageUpload' alt='' id='img2' name='img2' />");
    out.println("</body>");
    out.println("</html>");

in img tag's src i am calling same servlet and in doGet() get byte[] stored in session and send them back as following:

    response.setContentType("image/jpeg");
    byte[] byteArray =(byte[])request.getSession().getAttribute("image1");
    OutputStream output = response.getOutputStream(); 
    output.write(byteArray);
    output.close();

This code working fine in Mozilla but not working in IE only red X is being displayed but <img> tag is getting wide according to image size, but not displayed any thing.

Also, when I click submit button twice then the form is submitted in IE, in other words, it is being submitted in one click.

I am using IE-8 and image is of type JPEG.

Is there any setting issue? I tried to search on web, but no any result.


Solution

  • Actually i was using onload() event of body tag to open browse button automatically.

        <body onload='frm1.imgUpload.click()'>
     <form action="ImgUpload" method="POST" enctype="multipart/form-data" name="frm1"  id="frm1">
        <input type='file' id = 'imgUpload' name = 'imgUpload'  onchange='frm1.submit()' />
    </form>
       </body>
    

    but when i remove code for opening browse through java script it started working fine with IE i don't know what is the problem with IE and java script now i am clicking browse button manually and everything is working.