java文件上传

@ResponseBody  返回的是“application/json”形式的contentType,在ie浏览器中保存的时候会弹出下载框。所以应该去掉@ResponseBody注解。然后设置reponse.setContentType("text/html;charset=UTF-8");

@RequestMapping("/saveZjDictionary")
public void saveZjDictionary(String zjId, String editZjData, String addZjData,@RequestParam MultipartFile photo,HttpServletResponse response) throws SQLException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    tfsjService.saveZjDictionary(zjId, editZjData, addZjData, photo);
    PrintWriter out = response.getWriter();
    out.print("{success:true}");
}
out.print("{success:true}")是为了请求后台成功后执行success部分,如下是前台extjs中的代码:

me.uploadImagePanel.submit({
    url:__path + '/tfsj/saveZjDictionary.do',
    method:'POST',
    waitTitle : "提示信息",
    waitMsg: '正在保存...',
    params: {
        zjId: me.zjQueryGrid['专家_ID'] == undefined ? "" : me.zjQueryGrid['专家_ID'],
        editZjData: me.editZjData == "" ? "" : Ext.encode(me.editZjData),
        addZjData: me.addZjData == "" ? "" : Ext.encode(me.addZjData)
    },
    success: function(){
        me.zjQueryGrid['专家_ID'] = null;
        me.addZjData = [];
        me.editZjData = [];
        me.uploadImagePanel.getForm().reset();
        Ext.getCmp('browseImage').getEl().dom.src = '';
        me.ZjDictionaryStore.load({
            params: {
                zjId: ''
            }
        });
        me.zjQueryGrid.getStore().reload();
        Ext.Msg.alert("提示信息", "保存成功");
    },
    failure: function(){
        Ext.Msg.alert("提示信息", "保存失败");
    }
});



然后,怎样清除浏览器缓存呢?


@RequestMapping("/getZjPhoto")
public void getZjPhoto(HttpServletRequest request,HttpServletResponse response) throws SQLException, IOException {
    response.reset();
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);
    String zjId = request.getParameter("zjId");
    BufferedInputStream bufferedInputStream = tfsjService.getZjPhoto(zjId);
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
    if(bufferedInputStream != null){
        int i = 0;
        while ((i = bufferedInputStream.read()) != -1){
            bufferedOutputStream.write(i);
        }
        bufferedInputStream.close();
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值