上传文件 MultipartHttpServletRequest IE浏览器弹框保存

xiaoxiao2021-02-28  93

问题: 在有上传文件时的接口,前端请求后,部分ie浏览器会弹保存框,将请求变为下载类型。 经测试,在win7以下及自带为IE10以下易出现此问题。

解决: 在服务端java代码返回中修改如下:

public ResponseEntity<String> accreditHospital(MultipartHttpServletRequest req,HttpServletResponse response) { //业务代码 HttpHeaders responseHeaders = new HttpHeaders(); //responseHeaders.setContentType(MediaType.TEXT_HTML); responseHeaders.setContentType(new MediaType("text","html",Charset.forName("UTF-8"))); //此方式主要针对返回值乱码 Map<String,Object> result = new HashedMap(); result.put("hospitalId", hospitalId); result.put("success", true); String json = JsonUtil.object2Json(result); return new ResponseEntity<String>(json, responseHeaders, HttpStatus.OK); }

引入的包:

import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity;
转载请注明原文地址: https://www.6miu.com/read-54280.html

最新回复(0)