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.ewcms.component.comment.web.CounterServlet.java

private void initResponseHeader(final HttpServletResponse response, final String encoding) {
    response.setHeader("Content-Language", "zh-CN");
    String fullContentType = JSON_TYPE + ";charset=" + encoding;
    response.setContentType(fullContentType);
    //set on cache
    ///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:com.lcw.one.modules.sys.web.LoginController.java

/**
 * ?//from www .  j  a  v a  2  s  . c  o m
 */
@RequestMapping(value = "/validateCode", method = RequestMethod.GET)
public void validateCode(HttpServletRequest request, HttpServletResponse response) {
    ValidateCodeInterface validateCode = new EnCharValidateCode();
    try {
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        String code = validateCode.generate(80, 28, response.getOutputStream());
        request.getSession().setAttribute("ValidateCode", code);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.jboss.datavirt.commons.ui.header.DataVirtHeaderDataJS.java

/**
 * Make sure to tell the browser not to cache it.
 *
 * @param response//w  w  w .  ja  v  a2 s . co m
 */
private void noCache(HttpServletResponse response) {
    Date now = new Date();
    response.setDateHeader("Date", now.getTime());
    // one day old
    response.setDateHeader("Expires", now.getTime() - 86400000L);
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
}

From source file:com.music.web.MusicController.java

private void setNotCacheable(HttpServletResponse response) {
    response.setHeader("Pragma", "no-cache");
    // HTTP 1.0 header
    response.setDateHeader("Expires", 1L);
    // HTTP 1.1 header: "no-cache" is the standard value,
    // "no-store" is necessary to prevent caching on FireFox.
    response.setHeader("Cache-Control", "no-cache");
    response.addHeader("Cache-Control", "no-store");
}

From source file:com.portal.security.controller.JCaptchaController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String captchaId = request.getSession().getId();
    BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, request.getLocale());

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

    ImageIO.write(challenge, "jpeg", response.getOutputStream());

    /*//from w  ww.  j a va2s . c om
     * byte[] captchaChallengeAsJpeg = null; ByteArrayOutputStream jpegOutputStream = new
     * ByteArrayOutputStream();
     * 
     * JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
     * jpegEncoder.encode(challenge);
     * 
     * captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); ServletOutputStream
     * responseOutputStream = response.getOutputStream();
     * 
     * responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush();
     * responseOutputStream.close();
     */
    return null;
}

From source file:org.jasig.portal.security.mvc.LoginController.java

/**
 * Process the incoming HttpServletRequest
 * @param request//from w w w.  j av a  2  s .c o m
 * @param response
 * @exception ServletException
 * @exception IOException
 */
@RequestMapping
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);

    // create the redirect URL, adding fname and args parameters if necessary
    String redirectTarget = null;

    final String refUrl = request.getParameter(REFERER_URL_PARAM);
    if (refUrl != null) {
        if (refUrl.startsWith("/")) {
            redirectTarget = refUrl;
        } else {
            log.warn("Refernce URL passed in does not start with a / and will be ignored: " + refUrl);
        }
    }

    if (redirectTarget == null) {
        /* Grab the target functional name, if any, off the login request.
         * Also any arguments for the target
         * We will pass them  along after authentication.
         */
        String targetFname = request.getParameter("uP_fname");

        if (targetFname == null) {
            final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
            redirectTarget = defaultUrl.getUrlString();
        } else {
            try {
                final IPortalUrlBuilder urlBuilder = this.portalUrlProvider
                        .getPortalUrlBuilderByPortletFName(request, targetFname, UrlType.RENDER);

                @SuppressWarnings("unchecked")
                Enumeration<String> e = request.getParameterNames();
                while (e.hasMoreElements()) {
                    String paramName = e.nextElement();
                    if (!paramName.equals("uP_fname")) {
                        urlBuilder.addParameter(paramName, request.getParameterValues(paramName));
                    }
                }

                redirectTarget = urlBuilder.getUrlString();
            } catch (IllegalArgumentException e) {
                final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
                redirectTarget = defaultUrl.getUrlString();
            }
        }
    }

    IPerson person = null;

    final Object authError = request.getSession(false).getAttribute(LoginController.AUTH_ERROR_KEY);
    if (authError == null || !((Boolean) authError)) {
        person = this.personManager.getPerson(request);
    }

    if (person == null || !person.getSecurityContext().isAuthenticated()) {
        if (request.getMethod().equals("POST"))
            request.getSession(false).setAttribute(AUTH_ATTEMPTED_KEY, "true");
        // Preserve the attempted username so it can be redisplayed to the user by CLogin
        String attemptedUserName = request.getParameter("userName");
        if (attemptedUserName != null)
            request.getSession(false).setAttribute(ATTEMPTED_USERNAME_KEY, request.getParameter("userName"));
    }

    final String encodedRedirectURL = response.encodeRedirectURL(redirectTarget);
    response.sendRedirect(encodedRedirectURL);

}

From source file:com.buession.cas.web.controller.CaptchaController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.setContentType("image/jpg");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.setDateHeader("Expires", 0);

    String text = producer.createText();
    captchaService.add(request, text);/*  ww w. j a v  a2s  .c o  m*/

    BufferedImage im = producer.createImage(text);
    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(im, "jpg", out);

    try {
        out.flush();
    } finally {
        out.close();
    }

    return null;
}

From source file:org.overlord.commons.ui.header.OverlordHeaderDataJS.java

/**
 * Make sure to tell the browser not to cache it.
 *
 * @param response/*from   w  w w  .j a v a 2 s  .co m*/
 */
private void noCache(HttpServletResponse response) {
    Date now = new Date();
    response.setDateHeader("Date", now.getTime()); //$NON-NLS-1$
    // one day old
    response.setDateHeader("Expires", now.getTime() - 86400000L); //$NON-NLS-1$
    response.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
    response.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.ewcms.component.counter.web.CounterServlet.java

private void initResponseHeader(final HttpServletResponse response, final String encoding) {
    response.setHeader("Content-Language", "zh-CN");
    String fullContentType = JS_TYPE + ";charset=" + encoding;
    response.setContentType(fullContentType);
    //set on cache
    ///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:com.impala.servlet.Balance.java

/**
 * /*w w w . j a v  a  2  s  . c o  m*/
 * @param request
 * @param response
 * @throws ServletException
 *             , IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("text/plain;charset=UTF-8");
    response.setDateHeader("Expires", new Date().getTime()); // Expiration
    // date
    response.setDateHeader("Date", new Date().getTime()); // Date and time
    try {
        // that the
        // message was
        // sent
        out.write(moneytransfer(request).getBytes());
    } catch (JSONException ex) {
        Logger.getLogger(Remit.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.flush();
    out.close();
}