后台操作代码如下:/**
 * 还原图标
 * 
 * @param model
 * @param request
 * @param operation
 * @return
 */
@RequestMapping(value = Keys.SYS_SYSICON, params = "action=initPic")
public String initSysPagePic(Model model, HttpServletRequest request,
@RequestParam(value = "operation") int operation) {
String savePath = request.getServletContext().getRealPath(ICON_DIR);
String fileName = null;
if (operation == UPLOAD_LOGIN_PIC) {
fileName = LOGIN_PIC;
} else {
fileName = SYS_PIC;
}
int ret = -1;
File bak = new File(savePath + "/" + fileName + ".bak");
if (!bak.exists()) {
ret = 0;
} else {
new File(savePath + "/" + fileName).delete();
boolean isSuccess = bak
.renameTo(new File(savePath + "/" + fileName));
ret = isSuccess == true ? 0 : -1;

}
model.addAttribute(Keys.JSON_DATA, JsonUtil.toJSON(ret));
return Keys.AJAX_JSON;
}谢谢!

解决方案 »

  1.   

    点还原后整个页面有reload,而且图片请求后面带了时间戳。每次请求其实都是同一地址的
      

  2.   

    这个是页面加载延迟问题,有缓存的,你点击还原应该调用一个Ajax无刷新方法才可以,
    否则用普通方式改变加载到页面,肯定不会马上变化的,
    就像你每次修改一个页面,看效果的时候不都是要刷新几次才出来的,页面缓存是硬伤
      

  3.   

    <%
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragrma","no-cache");
    response.setDateHeader("Expires",0);
    %>
    我在面页加上了这段代码也不行啊
      

  4.   


    File oldFile = new File(savePath + "/" + fileName);
    System.gc();
    try {
    FileUtils.forceDelete(oldFile);
    System.gc();
     isSuccess = bak.renameTo(new File(savePath + "/" + fileName));
     jsonData= isSuccess == true ? JsonUtil.toJSON(0): JsonUtil.toJSON("Recover picture rename fail!",-1);
    Thread.sleep(2000);
    } catch (IOException e) {
    jsonData=JsonUtil.toJSON("ForceDelete picture fail", -1);
    logger.error("ForceDelete picture fail" + e);
    }catch (InterruptedException e) {
    jsonData=JsonUtil.toJSON("Recover picture thread interrupted", -1);
    logger.error("Recover picture thread interrupted" + e);
    } 这才是正解