简体   繁体   English

为什么已在IE中不显示上载的图像?

[英]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: 我使用简单的HTML页面上传和发布图像到servlet,然后将图像转换为byte []并使用doPost()方法保存在会话中:

        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: 在img标签的src中,我正在调用相同的servlet,在doGet()中,获取存储在会话中的byte []并将它们发送回,如下所示:

    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. 此代码在Mozilla中工作正常,但在IE中不工作,仅显示红色X,但img标签根据图像大小变宽,但未显示任何内容。 also when I click submit button twice then form get submitted in IE in other it is being submit in one click. 另外,当我单击提交按钮两次,然后在IE中以其他方式提交表单时,只需单击一下即可提交。

I am using IE-8 and image is of type .JPEG. 我正在使用IE-8,图像的类型为.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()事件自动打开浏览按钮的。

    <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. 但是,当我删除用于打开通过Java脚本浏览的代码时,它开始在IE中正常运行,我现在不知道IE和Java脚本有什么问题,我现在手动单击“浏览”按钮,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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