Example #1
1
  public void createImage(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpg");

    /** 取得高度和宽度 */
    String width = request.getParameter("width");
    String height = request.getParameter("height");

    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {

      w = NumberUtils.toInt(width);
      h = NumberUtils.toInt(height);
    }
    /** */
    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    createBackground(g);
    /** */
    String s = createCharacter(g);
    request.getSession().setAttribute(VALIDATE_CODE, s);
    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();
  }
Example #2
0
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (backupService == null) {
      SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }

    String url = ((HttpServletRequest) request).getRequestURI();
    if (isBackupFinishJsonUrl(url)) {
      ((HttpServletResponse) response).setHeader("Cache-Control", "private, max-age=0, no-cache");
      ((HttpServletResponse) response).setDateHeader("Expires", 0);
      generateResponseForIsBackupFinishedAPI(response);
      return;
    }
    if (backupService.isBackingUp()) {
      ((HttpServletResponse) response).setHeader("Cache-Control", "private, max-age=0, no-cache");
      ((HttpServletResponse) response).setDateHeader("Expires", 0);
      if (isAPIUrl(url) && !isMessagesJson(url)) {
        generateAPIResponse(request, response);
      } else {
        generateHTMLResponse(response);
      }
    } else {
      chain.doFilter(request, response);
    }
  }
Example #3
0
 @Override
 protected void setCacheHeaders(HttpServletResponse res) {
   long now = System.currentTimeMillis();
   res.setDateHeader(HttpHeaders.EXPIRES, now);
   res.setDateHeader(HttpHeaders.DATE, now);
   res.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=0, must-revalidate");
 }
 /**
  * Tell the browser to not cache.
  *
  * <p>This sets several headers to try to ensure that the page will not be cached. Not sure if
  * last modified matters -goliver
  *
  * @param response the HTTP response to which we will add headers.
  */
 @Override
 public void setNoCache(HttpServletResponse response) {
   long past = System.currentTimeMillis() - LONG_EXPIRE;
   response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store");
   response.setHeader(HttpHeaders.PRAGMA, "no-cache");
   response.setDateHeader(HttpHeaders.EXPIRES, past);
   response.setDateHeader(HttpHeaders.LAST_MODIFIED, past);
 }
Example #5
0
 /** 给HTTP响应头添加清空缓存标记. */
 public static void clearCache(HttpServletResponse response) {
   response.setHeader("Cache-Control", "no-cache");
   response.addHeader(
       "Cache-Control", "no-store"); // this is necessary to prevent caching on FireFox.
   response.setHeader("Pragma", "no-cache"); // HTTP 1.0
   response.setDateHeader("Expires", -1);
   response.setDateHeader("max-age", 0);
 }
 /**
  * Sets cache timeout to a given value.
  *
  * <p>This sets several headers to try to ensure that the page will be cached for the given length
  * of time. Of note is the last-modified header, which is set to a day ago so that browsers
  * consider it to be safe.
  *
  * @param response the HTTP response to which we will add headers.
  * @param expiration timeout value in milliseconds.
  */
 @Override
 public void setCacheTimeout(HttpServletResponse response, long expiration) {
   long now = System.currentTimeMillis();
   response.setHeader(HttpHeaders.VARY, "Accept-Encoding");
   response.setHeader(
       HttpHeaders.CACHE_CONTROL, String.format("max-age=%s, public", expiration / 1000));
   response.setDateHeader(HttpHeaders.EXPIRES, now + expiration);
   response.setDateHeader(HttpHeaders.LAST_MODIFIED, now - SHORT_EXPIRE);
 }
  protected void process(
      InputStream is, String path, HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    if (is != null) {
      Calendar cal = Calendar.getInstance();

      // check for if-modified-since, prior to any other headers
      long ifModifiedSince = 0;
      try {
        ifModifiedSince = request.getDateHeader("If-Modified-Since");
      } catch (Exception e) {
        log.warn(
            "Invalid If-Modified-Since header value: '"
                + request.getHeader("If-Modified-Since")
                + "', ignoring");
      }
      long lastModifiedMillis = lastModifiedCal.getTimeInMillis();
      long now = cal.getTimeInMillis();
      cal.add(Calendar.DAY_OF_MONTH, 1);
      long expires = cal.getTimeInMillis();

      if (ifModifiedSince > 0 && ifModifiedSince <= lastModifiedMillis) {
        // not modified, content is not sent - only basic
        // headers and status SC_NOT_MODIFIED
        response.setDateHeader("Expires", expires);
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        is.close();
        return;
      }

      // set the content-type header
      String contentType = getContentType(path);
      if (contentType != null) {
        response.setContentType(contentType);
      }

      if (serveStaticBrowserCache) {
        // set heading information for caching static content
        response.setDateHeader("Date", now);
        response.setDateHeader("Expires", expires);
        response.setDateHeader("Retry-After", expires);
        response.setHeader("Cache-Control", "public");
        response.setDateHeader("Last-Modified", lastModifiedMillis);
      } else {
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Expires", "-1");
      }

      try {
        copy(is, response.getOutputStream());
      } finally {
        is.close();
      }
      return;
    }
  }
  @RequestMapping(value = "/show-topics.jsp", method = RequestMethod.GET)
  public ModelAndView showUserTopics(
      @RequestParam("nick") String nick,
      @RequestParam(value = "offset", required = false) Integer offset,
      @RequestParam(value = "output", required = false) String output,
      HttpServletResponse response)
      throws Exception {
    Connection db = null;

    Map<String, Object> params = new HashMap<String, Object>();

    try {
      response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000);
      response.setDateHeader("Last-Modified", System.currentTimeMillis());

      db = LorDataSource.getConnection();

      User user = User.getUser(db, nick);

      params.put("ptitle", "Сообщения " + user.getNick());
      params.put("navtitle", "Сообщения " + user.getNick());

      params.put("user", user);

      NewsViewer newsViewer = new NewsViewer();

      offset = fixOffset(offset);

      newsViewer.setLimit("LIMIT 20" + (offset > 0 ? (" OFFSET " + offset) : ""));

      newsViewer.setCommitMode(NewsViewer.CommitMode.ALL);

      if (user.getId() == 2) {
        throw new UserErrorException("Лента для пользователя anonymous не доступна");
      }

      newsViewer.setUserid(user.getId());

      params.put("messages", newsViewer.getMessagesCached(db));

      params.put("offsetNavigation", true);
      params.put("offset", offset);

      params.put("rssLink", "show-topics.jsp?nick=" + nick + "&output=rss");

      if (output != null && output.equals("rss")) {
        return new ModelAndView("section-rss", params);
      } else {
        return new ModelAndView("view-news", params);
      }
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }
Example #9
0
 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
     throws IOException, ServletException {
   if (response instanceof HttpServletResponse) {
     HttpServletResponse res = (HttpServletResponse) response;
     res.setDateHeader("Expires", 0);
     res.setDateHeader("Last-Modified", new Date().getTime());
     res.setHeader("Cache-Control", "no-store, no-cache, max-age=0");
     res.setHeader("Pragma", "no-cache");
   }
   filterChain.doFilter(request, response);
 }
Example #10
0
  /**
   * Add an expires header to matching files to help browsers avoid reloading static files.
   * {@inheritDoc}
   */
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;

    long now = System.currentTimeMillis();
    // res being the HttpServletResponse of the request
    response.addHeader("Cache-Control", "max-age=" + CACHE_DURATION_IN_SECOND);
    response.addHeader("Cache-Control", "must-revalidate"); // optional
    response.setDateHeader("Last-Modified", now);
    response.setDateHeader("Expires", now + CACHE_DURATION_IN_MS);

    chain.doFilter(req, response);
  }
Example #11
0
 /**
  * Ajax请求(根据院系得到班级信息)
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return
  */
 public ActionForward findBjInfoByYx(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {
   String yxbh = request.getParameter("yxbh");
   response.setCharacterEncoding("utf-8");
   response.setDateHeader("Expires", 0);
   response.setHeader("Cache-Control", "no-cache");
   try {
     PrintWriter out = response.getWriter();
     List list = this.getIJcffglService().findBjInfoByYx(yxbh);
     String str = "";
     for (int i = 0; i < list.size(); i++) {
       Xs0206 xs0206 = (Xs0206) list.get(i);
       str += xs0206.getBjbh() + "#" + xs0206.getBjmc() + "$";
     }
     out.print(str);
     out.flush();
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
  // method will call when user clicks on the link given in email
  @RequestMapping(value = "/logoutOutAction")
  public String getIssueDetails(
      HttpSession session, HttpServletRequest request, HttpServletResponse response) {

    logger.info("---- Entered getIssueDetails() of LogoutController ----");

    try {
      session = request.getSession(false);
      response.setHeader(
          "Cache-Control",
          "no-cache"); // Forces caches to obtain a new copy of the page from the origin server
      response.setHeader(
          "Cache-Control",
          "no-store"); // Directs caches not to store the page under any circumstance
      response.setDateHeader("Expires", 0); // Causes the proxy cache to see the page as "stale"
      response.setHeader("Pragma", "no-cache"); // HTTP 1.0 backward compatibility
      session.removeAttribute(IssueTrackerConstants.ISSUETRACKERCONSTANTS_LOGIN_USER_SESSION_NAME);
      session.setAttribute(
          IssueTrackerConstants.ISSUETRACKERCONSTANTS_LOGIN_USER_SESSION_NAME, null);
      session.invalidate();
    } catch (Exception e) {
      e.printStackTrace();
      StringWriter errors = new StringWriter();
      e.printStackTrace(new PrintWriter(errors));
      logger.error(errors.toString());
    }

    return "logout";
  }
Example #13
0
  public static void serveFile(
      File file, String mimeType, HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    if (!file.exists()) {
      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
    if (file.isDirectory()) {
      response.setStatus(HttpServletResponse.SC_FORBIDDEN);
      return;
    }

    long lastMod = file.lastModified() / 1000 * 1000;
    long ifModSinc = request.getDateHeader(REQUEST_DATE_HEADER_IF_MOD_SINCE);
    // System.out.println("IF MOD SINCE "+new Date(ifModSinc));
    // System.out.println(file.getAbsolutePath()+" LAST MOD "+new Date(lastMod));
    if (lastMod <= ifModSinc) {
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;
    }

    response.setContentType(mimeType);
    response.setContentLength((int) file.length());
    response.setDateHeader(RESPONSE_DATE_HEADER_LAST_MOD, lastMod);
    FileInputStream in = new FileInputStream(file);
    OutputStream out = response.getOutputStream();
    byte[] buf = new byte[SERVE_BLOCK_SIZE];
    int count = 0;
    while ((count = in.read(buf)) >= 0) {
      out.write(buf, 0, count);
    }
    in.close();
    out.close();
  }
  @RequestMapping(value = "/getValidateCode.action", method = RequestMethod.GET)
  public void getValidateCode(HttpServletRequest req, HttpServletResponse resp) {
    try {
      // 设置响应的类型格式为图片格式
      resp.setContentType("image/jpeg");
      // 禁止图像缓存。
      resp.setHeader("Pragma", "no-cache");
      resp.setHeader("Cache-Control", "no-cache");
      resp.setDateHeader("Expires", 0);

      HttpSession session = req.getSession();

      ValidateCode vCode = new ValidateCode(60, 18, 4, 20);
      session.setAttribute("validateCode", vCode.getCode());
      // log.info("验证码为:[" + vCode.getCode() + "]");
      vCode.write(resp.getOutputStream());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      log.error(e);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      log.error(e);
    }
  }
Example #15
0
 public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String createTypeFlag = request.getParameter("createTypeFlag"); // 接收客户端传递的createTypeFlag标识
   // 1.在内存中创建一张图片
   BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
   // 2.得到图片
   Graphics g = bi.getGraphics();
   // 3.设置图片的背影色
   setBackGround(g);
   // 4.设置图片的边框
   setBorder(g);
   // 5.在图片上画干扰线
   drawRandomLine(g);
   // 6.写在图片上随机数
   // String random = drawRandomNum((Graphics2D) g,"ch");//生成中文验证码图片
   // String random = drawRandomNum((Graphics2D) g,"nl");//生成数字和字母组合的验证码图片
   // String random = drawRandomNum((Graphics2D) g,"n");//生成纯数字的验证码图片
   // String random = drawRandomNum((Graphics2D) g,"l");//生成纯字母的验证码图片
   String random =
       drawRandomNum((Graphics2D) g, createTypeFlag); // 根据客户端传递的createTypeFlag标识生成验证码图片
   // 7.将随机数存在session中
   request.getSession().setAttribute("checkcode", random);
   // 8.设置响应头通知浏览器以图片的形式打开
   response.setContentType("image/jpeg"); // 等同于response.setHeader("Content-Type",
   // "image/jpeg");
   // 9.设置响应头控制浏览器不要缓存
   response.setDateHeader("expries", -1);
   response.setHeader("Cache-Control", "no-cache");
   response.setHeader("Pragma", "no-cache");
   // 10.将图片写给浏览器
   ImageIO.write(bi, "jpg", response.getOutputStream());
 }
Example #16
0
 protected void service(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   res.setHeader("Pragma", "no-cache");
   res.setHeader("Cache-Control", "no-cache");
   res.setDateHeader("Expires", 0);
   super.service(req, res);
 }
Example #17
0
 private HttpServletResponse prepareSendResponse() {
   HttpServletResponse response = getResponse();
   response.setContentType("text/json;charset=utf-8");
   response.setCharacterEncoding("UTF-8");
   response.setDateHeader("Expires", 0);
   return response;
 }
Example #18
0
 /** 设置禁止客户端缓存的Header. */
 public static void setNoCacheHeader(HttpServletResponse response) {
   // Http 1.0 header
   response.setDateHeader(HttpHeaders.EXPIRES, 1L);
   response.addHeader(HttpHeaders.PRAGMA, "no-cache");
   // Http 1.1 header
   response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0");
 }
Example #19
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // 不要让浏览器开辟缓存
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    // 程序立即过期
    response.setDateHeader("Expires", 0);
    // 不要让浏览其缓存程序
    response.setHeader("Pragma", "no-cache");
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    String username = request.getParameter("username");
    double money = Double.parseDouble(request.getParameter("money"));
    PrintWriter out = response.getWriter();
    int id = ((User) request.getSession().getAttribute("user")).getId();
    if (username != null
        && username != ""
        && request.getParameter("money") != null
        && request.getParameter("money") != "") {
      try {
        User user = UserServiceImpl.getInstance().transfer(username, money, id);
        request.getSession().setAttribute("user", user);
      } catch (UserNotFoundException e) {
        out.print("用户名不存在");
      } catch (MoneyNotEnoughException e) {
        out.print("余额不足");
      }
    } else {
      out.print("存在空选项,无法进行提交!");
    }
    out.flush();
    out.close();
  }
Example #20
0
 /** 设置客户端缓存过期时间 的Header. */
 public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
   // Http 1.0 header, set a fix expires date.
   response.setDateHeader(
       HttpHeaders.EXPIRES, System.currentTimeMillis() + (expiresSeconds * 1000));
   // Http 1.1 header, set a time after now.
   response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=" + expiresSeconds);
 }
Example #21
0
 private void generateExpireResponseHeaders(HttpServletResponse res, boolean expireResponse) {
   if (expireResponse) {
     res.setHeader("Pragma", "no-cache");
     res.setDateHeader("Expires", 0);
     res.setHeader("Cache-Control", "no-cache");
   }
 }
 public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
   response.setStatus(HttpServletResponse.SC_OK);
   String vsName = request.getParameter("name");
   VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
   if (logger.isInfoEnabled())
     logger.info(
         new StringBuilder()
             .append("Structure request for *")
             .append(vsName)
             .append("* received.")
             .toString());
   StringBuilder sb = new StringBuilder("<virtual-sensor name=\"").append(vsName).append("\">\n");
   for (DataField df : sensorConfig.getOutputStructure())
     sb.append("<field name=\"")
         .append(df.getName())
         .append("\" ")
         .append("type=\"")
         .append(df.getType())
         .append("\" ")
         .append("description=\"")
         .append(StringEscapeUtils.escapeXml(df.getDescription()))
         .append("\" />\n");
   sb.append(
       "<field name=\"timed\" type=\"string\" description=\"The timestamp associated with the stream element\" />\n");
   sb.append("</virtual-sensor>");
   response.setHeader("Cache-Control", "no-store");
   response.setDateHeader("Expires", 0);
   response.setHeader("Pragma", "no-cache");
   response.getWriter().write(sb.toString());
 }
Example #23
0
 /**
  * 根据院系查找专业
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return
  */
 public ActionForward findZyByYx(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {
   String yxbh = request.getParameter("yxbh");
   String pycc = request.getParameter("pycc");
   List list = this.getIJcffglService().findZyByYx(yxbh, pycc);
   response.setCharacterEncoding("utf-8");
   response.setDateHeader("Expires", 0);
   response.setHeader("Cache-Control", "no-cache");
   String str = "";
   try {
     PrintWriter out = response.getWriter();
     for (int i = 0; i < list.size(); i++) {
       Jx01 jx01 = (Jx01) list.get(i);
       str += jx01.getZybh() + "," + jx01.getZymc() + "#";
     }
     out.println(str);
     out.flush();
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #24
0
 /**
  * Internet Explorer file downloads over SSL do not work with certain HTTP cache control headers
  *
  * <p>See http://support.microsoft.com/kb/323308/
  *
  * <p>What is not mentioned in the above Knowledge Base is that "Pragma: no-cache" also breaks
  * download in MSIE over SSL
  */
 private static void addCacheControlHeaders(
     HttpServletRequest request, HttpServletResponse response) {
   String userAgent = request.getHeader("User-Agent");
   boolean secure = request.isSecure();
   if (!secure) {
     String nvh = request.getHeader(VH_HEADER);
     if (nvh == null) {
       nvh = Framework.getProperty(VH_PARAM);
     }
     if (nvh != null) {
       secure = nvh.startsWith("https");
     }
   }
   log.debug("User-Agent: " + userAgent);
   log.debug("secure: " + secure);
   if (userAgent.contains("MSIE") && (secure || forceNoCacheOnMSIE())) {
     log.debug("Setting \"Cache-Control: max-age=15, must-revalidate\"");
     response.setHeader("Cache-Control", "max-age=15, must-revalidate");
   } else {
     log.debug("Setting \"Cache-Control: private\" and \"Pragma: no-cache\"");
     response.setHeader("Cache-Control", "private, must-revalidate");
     response.setHeader("Pragma", "no-cache");
     response.setDateHeader("Expires", 0);
   }
 }
Example #25
0
 /**
  * 根据班级查找学生
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return
  */
 public ActionForward findStuByBj(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {
   String bjbh = request.getParameter("bjbh");
   List list = this.getIJcffglService().findStuByBj(bjbh);
   response.setCharacterEncoding("utf-8");
   response.setDateHeader("Expires", 0);
   response.setHeader("Cache-Control", "no-cache");
   String str = "";
   try {
     PrintWriter out = response.getWriter();
     for (int i = 0; i < list.size(); i++) {
       Xs0101 xs0101 = (Xs0101) list.get(i);
       str += xs0101.getXsbh() + "," + xs0101.getXm() + "#";
     }
     out.println(str);
     out.flush();
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
  // 上传文件数据处理过程
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
      logger.debug("type=" + request.getParameter("type"));
      logger.debug("ptype=" + request.getParameter("ptype"));
      logger.debug("puid=" + request.getParameter("puid"));
      logger.debug("absolute=" + "1".equals(request.getParameter("a")));
    }

    // 防止缓存的设置
    response.setContentType("text/html; charset=UTF-8");
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);

    if ("application/octet-stream".equals(request.getContentType())) {
      logger.debug("doPost4Html5");
      // HTML5上传
      doPost4Html5(request, response);
    } else {
      logger.debug("doPost4Html4");
      // HTML4普通文件上传
      doPost4Html4(request, response);
    }
  }
  /**
   * This method is requesting the front page since that is all this servlet does (apart from config
   * initialisation and sharing). Return it here.
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse response)
      throws ServletException, IOException {
    /* HTTP 1.1 */
    response.setHeader("Cache-Control", "no-cache");
    /* HTTP 1.0 */
    response.setHeader("Pragma", "no-cache");
    /* Prevents caching at the proxy server */
    response.setDateHeader("Expires", 0);
    /*
     * Just return the front page. If we want some more (dynamic) web pages
     * available here, we need to do some extra handling of what the URL
     * actually says
     */
    Template template = velocityEngine.getTemplate("templates/index.vm");
    VelocityContext context = new VelocityContext();
    EventCartridge ec = new EventCartridge();
    ec.addEventHandler(new EscapeHtmlReference());
    ec.attachToContext(context);

    context.put("catalogue", catalogue);
    context.put("config", catalogue.getConfig());
    context.put("GISUtils", GISUtils.class);
    context.put("supportedImageFormats", ImageFormat.getSupportedMimeTypes());
    template.merge(context, response.getWriter());
  }
Example #28
0
 /**
  * Set the no-cache headers for all responses, if requested. <strong>NOTE</strong> - This header
  * will be overridden automatically if a <code>RequestDispatcher.forward</code> call is ultimately
  * invoked.
  *
  * @param request The servlet request we are processing
  * @param response The servlet response we are creating
  */
 protected void processNoCache(HttpServletRequest request, HttpServletResponse response) {
   if (moduleConfig.getControllerConfig().getNocache()) {
     response.setHeader("Pragma", "No-cache");
     response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
     response.setDateHeader("Expires", 1);
   }
 }
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    httpResponse.setHeader("Cache-Control", "max-age=" + CACHE_TIME_TO_LIVE + ", public");
    httpResponse.setHeader("Pragma", "cache");

    // Setting Expires header, for proxy caching
    httpResponse.setDateHeader("Expires", CACHE_TIME_TO_LIVE + System.currentTimeMillis());

    // Setting the Last-Modified header, for browser caching
    httpResponse.setDateHeader("Last-Modified", LAST_MODIFIED);

    chain.doFilter(request, response);
  }
Example #30
0
 /** 设置禁止客户端缓存的Header. */
 public static void setDisableCacheHeader(HttpServletResponse response) {
   // Http 1.0 header
   response.setDateHeader("Expires", 1L);
   response.addHeader("Pragma", "no-cache");
   // Http 1.1 header
   response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
 }