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

  • 相关阅读:
    PKU1008
    PKU 1007
    PKU 3983
    PKU 1005
    PKU1004
    PKU 1003解题
    new.target
    debugger 关键字
    React 高阶组件
    CSS|规范
  • 原文地址:https://www.cnblogs.com/yuananyun/p/6402828.html
Copyright © 2011-2022 走看看