zoukankan      html  css  js  c++  java
  • IE8+SpringMVC文件上传防止JSON下载

    今天在IE8测试文件上传的时候发现总是提示下载,原因是上传接口返回的是json,通过以下修改就可以保证返回是json并且不会出现下载的情况:

        @RequestMapping(value = "/batchUpload", method = RequestMethod.POST,produces = "text/json;charset=UTF-8")
        @ResponseBody
        public Object batchUpload(@RequestParam String orderId, @RequestParam("file") MultipartFile file, HttpServletResponse response) {
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("X-Frame-Options", "SAMEORIGIN");
            response.setHeader("Access-Control-Allow-Origin", "*");
            
            String filePath = fileUploadService.upload(file);
            Map result = new HashedMap();
            if (filePath == null) {
                result.put("status", 0);
            } else {
                result.put("status", 1);
                result.put("filePath", filePath);
            }
            return JSON.toJSONString(result);
        }

    What is the exact difference between content-type: text/json and application/json? 

    application/json: Official MIME type for json

    text/x-json: Experimental(unofficial) MIME type for json before application/json got officially registered

  • 相关阅读:
    8.8集训
    8.7集训
    8.6集训
    poj 2492
    埃氏筛法
    并查集板子
    2018级程序能力实训第二次上机考试
    网络流
    活动安排问题
    等价类
  • 原文地址:https://www.cnblogs.com/yuananyun/p/6402828.html
Copyright © 2011-2022 走看看