简体   繁体   中英

Why Uploaded Image not being displayed in IE?

I am using simple HTML page for upload and post image to servlet then I convert image in byte[] and save 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 form get submitted in IE in other it is being submit in one click.

I am using IE-8 and image is of type .JPEG. is there is any setting issue I tried to search on web but no any result.

您的问题是您关闭了输出流,因此它无法继续加载。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM