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.kappaware.logtrawler.Utils.java

public static void setCache(HttpServletResponse response, int cacheValue) {
    if (cacheValue == 0) {
        response.setHeader(HEADER_PRAGMA, "no-cache");
        // HTTP 1.0 header
        response.setDateHeader(HEADER_EXPIRES, 1L);
        // HTTP 1.1 header: "no-cache" is the standard value,
        // "no-store" is necessary to prevent caching on FireFox.
        response.setHeader(HEADER_CACHE_CONTROL, "no-cache");
        response.addHeader(HEADER_CACHE_CONTROL, "no-store");
        response.addHeader(HEADER_CACHE_CONTROL, "must-revalidate");
        response.addHeader(HEADER_CACHE_CONTROL, "post-check=0");
        response.addHeader(HEADER_CACHE_CONTROL, "pre-check=0");

    } else {/*from   www.ja v  a  2s.c  o  m*/
        response.setHeader(HEADER_CACHE_CONTROL, "public");
        long now = (new Date()).getTime();
        response.setDateHeader("Date", now);
        response.setDateHeader(HEADER_EXPIRES, now + (cacheValue * 1000L));
        // HTTP 1.1 header
        String headerValue = "max-age=" + Long.toString(cacheValue);
        response.setHeader(HEADER_CACHE_CONTROL, headerValue);
    }
}

From source file:com.xsw.utils.Servlets.java

/**
 *  Header./* ww  w .j ava 2  s  .  c o m*/
 */
public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
    // Http 1.0 header, set a fix expires date.
    response.setDateHeader("Expires", System.currentTimeMillis() + expiresSeconds * 1000);
    // Http 1.1 header, set a time after now.
    response.setHeader("Cache-Control", "private, max-age=" + expiresSeconds);
}

From source file:dk.dma.msinm.common.util.WebUtils.java

/**
 * Add headers to the response to ensure caching in the given duration
 * @param response the response//from   ww w .  ja v a 2  s  .c o m
 * @param seconds the number of seconds to cache the response
 * @return the response
 */
public static HttpServletResponse cache(HttpServletResponse response, int seconds) {
    long now = System.currentTimeMillis();
    response.addHeader("Cache-Control", "max-age=" + seconds);
    response.setDateHeader("Last-Modified", now);
    response.setDateHeader("Expires", now + seconds * 1000L);
    return response;
}

From source file:jp.go.nict.langrid.foundation.servlet.ResponseProcessor.java

private static void addFaultHeader(HttpServletResponse response) {
    response.setStatus(500);// ww  w.ja  va2  s .c  o  m
    response.setContentType("text/xml; charset=utf-8");
    response.setHeader("Server", "LanguageGrid-CoreNode/1.0");
    response.setDateHeader("Date", new Date().getTime());
}

From source file:com.sobey.framework.utils.Servlets.java

/**
 *  Header.//from  w  ww . j  a  v  a 2 s  .  c  om
 */
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);

}

From source file:com.cnksi.core.web.utils.Servlets.java

/**
 *  Header./*from   w w  w.java  2 s. c  o m*/
 */
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);
}

From source file:dk.dma.msinm.common.util.WebUtils.java

/**
 * Add headers to the response to ensure no caching takes place
 * @param response the response/*w w  w. j av a  2  s  . c  om*/
 * @return the response
 */
public static HttpServletResponse nocache(HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    return response;
}

From source file:com.lll.util.ServletUtils.java

/**
 * Header.//  w w  w  . ja v  a2 s.  c o m
 */
public static void setNoCacheHeader(HttpServletResponse response) {
    //Http 1.0 header
    response.setDateHeader("Expires", 0);
    response.addHeader("Pragma", "no-cache");
    //Http 1.1 header
    response.setHeader("Cache-Control", "no-cache");
}

From source file:org.jahia.utils.WebUtils.java

/**
 * Sets proper response headers to prevent caching of this response.
 * /*from  w  w  w  . j a  v  a 2 s  .  c om*/
 * @param response
 *            current response object
 */
public static void setNoCacheHeaders(HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, proxy-revalidate, max-age=0");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 295075800000L);
}

From source file:com.klwork.common.utils.WebUtils.java

/**
 * ???//from w  ww.j av  a 2  s.  c  om
 * @param request
 * @param response
 */
public static void VerificationCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    // 
    int width = 60, height = 20;
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    // ?
    Graphics g = image.getGraphics();

    // ??
    Random random = new Random();

    // 
    g.setColor(getRandColor(200, 250));
    g.fillRect(0, 0, width, height);

    // 
    g.setFont(new Font("Times New Roman", Font.PLAIN, 18));

    // 
    // g.setColor(new Color());
    // g.drawRect(0,0,width-1,height-1);

    // ?155?????
    g.setColor(getRandColor(160, 200));
    for (int i = 0; i < 155; i++) {
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
    }

    String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQUSTUVWXYZ0123456789";
    // ????(4?)
    String sRand = "";
    for (int i = 0; i < 4; i++) {
        int start = random.nextInt(base.length());
        String rand = base.substring(start, start + 1);
        sRand = sRand.concat(rand);
        // ??
        g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        g.drawString(rand, 13 * i + 6, 16);
    }

    // ??SESSION
    request.getSession().setAttribute("entrymrand", sRand);

    // 
    g.dispose();
    OutputStream out = response.getOutputStream();
    // ?
    ImageIO.write(image, "JPEG", out);

    out.flush();
    out.close();
}