【问题标题】:valums fileuploader doesnt work under IE 9 using spring使用 spring 的 IE 9 下,valuems 文件上传不起作用
【发布时间】:2012-07-22 10:47:50
【问题描述】:

我正在使用 spring MVC 进行文件上传,它在 Firefox 和 chrome 中工作正常,但在 IE 中它显示上传失败.. 下面是我的 jsp 页面,其中我包含 fileuploader 函数。

<div id="file-uploader-demo1" style="float: left;padding-top: 10px"></div>      

</div>

 <script>        
    function createUploader(){            
        var uploader = new qq.FileUploader ({
            element: document.getElementById('file-uploader-demo1'),
            action: '/Flas_ _/commu-____/insertFile;jsessionid=${sessionId}',
            headers: {'Content-type':'multipart/form-data'},
            multipleFileUpload: false,
            debug: true
        });           
    }
    window.onload = createUploader;     
</script> 

这是我的 jsp 页面,其中 iam 包括 FileUploader.js 文件,动作标签调用我各自的控制器,如下所示..

 @RequestMapping(value = "/insertFile", method = RequestMethod.POST)
public String fileUpload(@RequestParam("qqfile") String filename1,ModelMap map, 
        HttpServletRequest request,HttpServletResponse response) throws IOException {



    PrintWriter writer = null;
    InputStream is = null;
    FileOutputStream fos = null;

      try {
            writer = response.getWriter();
        } catch (IOException ex) {
            //log(OctetStreamReader.class.getName() + "has thrown an exception: " + ex.getMessage());
        }
      String filename =  request.getHeader("X-File-Name");
      this.setFILEUPLOAD(filename);
      try {
            is = request.getInputStream();
            fos = new FileOutputStream(new File("F:/images/" + filename));
            IOUtils.copy(is, fos);
            response.setStatus(response.SC_OK);
            writer.print("{success: true}");
        } catch (FileNotFoundException ex) {
            response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
          //  log(OctetStreamReader.class.getName() + "has thrown an exception: " + ex.getMessage());
        }catch (IOException ex) {
            response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
           // log(OctetStreamReader.class.getName() + "has thrown an exception: " + ex.getMessage());
        }  finally {
            try {
                fos.close();
                is.close();
            } catch (IOException ignored) {
            }
        }
      writer.flush();
        writer.close();

    return "do-nothing";
}

虽然在 CHROME 和 FIREFOX 中它工作正常,我将文件存储在语言环境驱动器中。但它在 IE 9 中不起作用。我应该怎么做我没有得到。

dis 的任何解决方案?请帮忙谢谢。

【问题讨论】:

    标签: ajax jsp spring-mvc file-upload


    【解决方案1】:

    我通过实现两个控制器方法解决了另一个问题(在 IE 中工作,在 FF 中不工作)。我没有发送带有 JavaScript 上传器配置的 explizit 标头。

    一种方法(对于 IE)有额外的 RequestMapping-Options: headers = { "content-type=multipart/form-data" }

    IE 的 RequestParam 是 MultipartFile。从中您将获得文件名和内容。 IE 使用的普通分段上传的请求正文不仅仅包含文件内容,就像使用 Firefox 的 ajax 上传一样。它还具有文件名和边界等多部分信息。 MultipartFile 可以为您处理。

    据我所知,必须进行一些常规设置才能使您的 webapp 处理多部分文件上传。但这是另一个问题。

    【讨论】:

      猜你喜欢
      • 2011-12-09
      • 2013-03-03
      • 1970-01-01
      • 2015-12-04
      • 2013-12-27
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      相关资源
      最近更新 更多