您的位置:首页 > Web前端 > JavaScript

DWZ框架在IE下进行文件上传,提醒JSON文件下载问题

2017-01-06 17:27 288 查看
【问题现象】使用DWZ框架上传文件:

<form method="post"  action="" class="pageForm required-validate" enctype="multipart/form-data" onsubmit="iframeCallback(this, customAjaxDone);">
<div class="pageFormContent">
<p>
<label>导入:</label>
<input name="file" class="valid" type="file">
</p>
<div class="buttonActive"><div class="buttonContent"><button type="submit">提交</button></div></div>
</div>
</form>


dwz在做无刷新文件上传时,是通过隐藏iframe去做文件提交的

后台处理请求返回JSON

@RequestMapping(value = "import/{navTabId}/{type}", method = RequestMethod.POST)
@ResponseBody
public Object importFile(@RequestParam(value = "file") MultipartFile file, @PathVariable String type, @PathVariable String navTabId,HttpServletResponse response) {
...
}


在IE浏览器会提示json文件的下载提醒

【问题解决】 由于json默认返回的响应头为“Content-Type: application/json;charset=UTF-8”导致了 IE会有这个问题

采用的解决办法就是去更改响应头

//  json格式化
ObjectMapper objectMapper = new ObjectMapper();
// 设置响应头
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = null;
try {
String result = objectMapper.writeValueAsString(dwzResult);
out = response.getWriter();
out.write(result);
out.flush();
} catch (IOException e) {
logger.error("IOException", e);
} finally {
if (out != null) {
out.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DWZ IE
相关文章推荐