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

【问题现象】使用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();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值