Example usage for javax.servlet.http HttpServletResponse setDateHeader

List of usage examples for javax.servlet.http HttpServletResponse setDateHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setDateHeader.

Prototype

public void setDateHeader(String name, long date);

Source Link

Document

Sets a response header with the given name and date-value.

Usage

From source file:com.sunchenbin.store.feilong.servlet.http.ResponseUtil.java

/**
 * ??./*from  w w  w . j av  a  2s .co  m*/
 *
 * @param response
 *            HttpServletResponse
 */
public static void setNoCacheHeader(HttpServletResponse response) {
    // HTTP1.1? CacheControl = no-cache??
    // ? HTTP1.0 ?? Cache-Control 

    // ?? HTTP1.0 ?IEPragma:no-cache  HTTP???
    //  (https://)/??? Pragma:no-cache  Internet Explorer??
    // ?Pragma:no-cache ???? Expires:-1??
    response.setHeader(HttpHeaders.PRAGMA, "No-cache");

    // Cache-controlno-cache???Internet?
    response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");

    //In other wordsExpires: 0not always leads to immediate resource expiration, 
    //therefore should be avoided andExpires: -1orExpires: [some valid date in the past]should be used instead.
    response.setDateHeader(HttpHeaders.EXPIRES, -1);
}

From source file:com.sharmila.hibernatespringsecurity.controller.DefaultController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView defaultPage(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout, HttpServletRequest request,
        HttpServletResponse response) {
    ModelAndView model = new ModelAndView();
    if (error != null) {
        model.addObject("error", "Invalid user credentials");
    }/*from  w  ww  .j  a  va 2 s . c om*/
    if (logout != null) {
        model.addObject("message", "Logged out successfully");
        request.getSession().invalidate();
    }

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    model.setViewName("login");
    return model;
}

From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java

/**
 * Sets the appropriate headers to response of this request.
 *
 * @param response The HttpServletResponse response object.
 *//*from w  w  w  .ja v a2s.  c o m*/
private void setResponeHeaders(HttpServletResponse response) {

    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", System.currentTimeMillis());
    response.setContentType("text/plain; charset=utf-8");
    response.setCharacterEncoding("utf-8");
}

From source file:org.silverpeas.web.directory.servlets.ImageDisplay.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    SilverLogger logger = SilverLogger.getLogger(this);
    String avatarPath = getAvatar(req);
    ImageProfil profile = new ImageProfil(avatarPath);
    if (!profile.exist()) {
        logger.warn("The image {0} doesn't exist", avatarPath);
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {//from  w  w  w  .  j av  a2s.c  o m
        res.setContentType(profile.getMimeType());
        res.setHeader("Cache-Control", "no-store"); //HTTP 1.1
        res.setHeader("Pragma", "no-cache");
        res.setDateHeader("Expires", -1);
        try (InputStream in = profile.getImage(); OutputStream out = res.getOutputStream()) {
            IOUtils.copy(in, out);
        } catch (IOException e) {
            logger.error("Error while getting image {0}", avatarPath);
            throw e;
        }
    }
}

From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from  w  w  w .j a  v  a  2 s.  co m*/
        int width = 50;
        int height = 18;
        String captchaCode = RandomStringUtils.random(4, true, true);
        HttpSession session = request.getSession(true);
        session.setAttribute("captchaCode", captchaCode);

        response.setContentType("images/jpeg");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);

        ServletOutputStream out = response.getOutputStream();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(getRandColor(200, 250));
        g.fillRect(0, 0, width, height);
        Font mFont = new Font("Times New Roman", Font.BOLD, 18);
        g.setFont(mFont);
        g.setColor(getRandColor(160, 200));
        Random random = new Random();
        for (int i = 0; i < 155; i++) {
            int x2 = random.nextInt(width);
            int y2 = random.nextInt(height);
            int x3 = random.nextInt(12);
            int y3 = random.nextInt(12);
            g.drawLine(x2, y2, x2 + x3, y2 + y3);
        }
        g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        g.drawString(captchaCode, 2, 16);
        g.dispose();
        ImageIO.write((BufferedImage) image, "JPEG", out);
        out.close();
    } catch (Exception e) {
        logger.error("Generate captcha failed.", e);
    }
}

From source file:com.library.essay.tinymce.spellchecker.TinyMCESpellCheckerServlet.java

/**
 * @param response response//w w  w. j  a v  a 2s  .  c  om
 */
private void setResponeHeaders(HttpServletResponse response) {
    response.setContentType("text/plain; charset=utf-8");
    response.setCharacterEncoding("utf-8");
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", System.currentTimeMillis());
}

From source file:com.vmware.appfactory.common.base.AbstractController.java

/**
 * Set HTTP headers on an HTTP response to hopefully force browsers to
 * prevent the response being cached. Especially important for dynamic
 * content updates. We're talking to you, Internet Explorer.
 *///from w  w w .  j  a  v  a 2s.co m
protected void setNoCacheHeaders(HttpServletResponse response) {
    response.addHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    response.setDateHeader("Expires", 0);
}

From source file:be.fedict.eid.dss.sp.servlet.DownloadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOG.debug("doGet");
    HttpSession httpSession = request.getSession();
    byte[] document = (byte[]) httpSession.getAttribute("document");

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1
    if (!request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {/*from  w  w w.ja v a  2s.  co  m*/
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);
    response.setContentLength(document.length);

    String contentType = (String) httpSession.getAttribute("ContentType");
    LOG.debug("content-type: " + contentType);
    response.setContentType(contentType);
    response.setContentLength(document.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(document);
    out.flush();
}

From source file:custom.application.login.java

public void toImage() {

    HttpServletRequest request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST");
    HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");

    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);

    try {/*from  w w w.j  ava  2s.  c  om*/
        ValidateCode code = new ValidateCode(request);
        code.toImage(response);
    } catch (java.io.IOException io) {
        io.printStackTrace();
    }
}

From source file:org.romaframework.aspect.view.html.HtmlServlet.java

protected void setResponseHeaders(final HttpServletResponse response) {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    // response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); //HTTP 1.1
    response.addHeader("Cache-Control", "must-revalidate");
    response.addHeader("Cache-Control", "no-cache");
    response.addHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0
    response.setDateHeader("Expires", 0); // prevents caching at the proxy server
}