@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(); } }