今天在IE8测试文件上传的时候发现总是提示下载,原因是上传接口返回的是json,通过以下修改就可以保证返回是json并且不会出现下载的情况:
同时适用于当设置SPRING 视图解析器的时候,不能去掉@responseBody的问题
@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); }