Example usage for javax.servlet.http HttpServletResponse setHeader

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

Introduction

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

Prototype

public void setHeader(String name, String value);

Source Link

Document

Sets a response header with the given name and value.

Usage

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

/**
 * ??Header./*  w ww.j  a v a2s. c o  m*/
 * 
 * @param fileName
 *            ???.
 */
public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {
    try {

        // ???

        String encodedfileName = new String(fileName.getBytes(), "ISO8859-1");

        response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");

    } catch (UnsupportedEncodingException e) {
    }
}

From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java

/**
 * Sets the document name putting it into the Content-Disposition header
 * //from  w  w w.j a v a 2 s  .c om
 * @param response HTTP response
 * @param method HTTP method
 */
public static void setDocumentName(HttpServletResponse response, HttpMethodBase method, String contentType) {
    response.setHeader("Content-Type", contentType);
    //Set the file name properly
    String[] tabpath = (method.getPath()).split("/");
    String fileName = tabpath[tabpath.length - 1];
    String decodeFileName = null;
    try {
        decodeFileName = URLDecoder.decode(fileName, "UTF-8");
    } catch (Exception e) {
        logger.error("Exception decoding URL: " + e);
        decodeFileName = fileName;
    }
    response.setHeader("Content-Disposition", "inline; filename=" + decodeFileName);
}

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

/**
 * ??Header./* w  ww.j ava  2s.  c o m*/
 * 
 * @param fileName ???.
 */
public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {

    try {
        // ???
        String encodedfileName = new String(fileName.getBytes(), "ISO8859-1");
        response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");
    } catch (UnsupportedEncodingException e) {
    }
}

From source file:cn.com.qiqi.order.utils.Servlets.java

/**
 * ?Header./*  w  w  w  . ja  va2s  .c om*/
 */
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");
}

From source file:com.ykun.commons.utils.excel.ExcelUtils.java

/**
 * xlscontent-type/*from ww w.  j ava 2  s . com*/
 *
 * @param response
 * @param fileName
 * @throws IOException
 */
private static void setContentType(HttpServletResponse response, String fileName) throws IOException {
    response.setContentType(CONTENT_TYPE);
    response.setHeader(HEADER_CONTENT_DISPOSITION,
            MessageFormat.format(PATTERN_DISPOSITION, URLEncoder.encode(fileName, CHARSET_UTF8)));
}

From source file:com.sap.data.core.web.Servlets.java

/**
 *  Header./*from w ww. j  a  v  a 2s .  co 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:com.cnksi.core.web.utils.Servlets.java

/**
 * ?Header./* w  w  w  . ja  v a  2  s.  c o  m*/
 */
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");
}

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

/**
 * ?Header./*w ww.  j a v  a 2  s .  co m*/
 */
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");
}

From source file:io.apicurio.studio.fe.servlet.servlets.DownloadServlet.java

/**
 * Disable caching.//from  w  w w .ja  va 2  s.c om
 * @param httpResponse
 */
private static void disableHttpCaching(HttpServletResponse httpResponse) {
    Date now = new Date();
    httpResponse.setDateHeader("Date", now.getTime()); //$NON-NLS-1$
    httpResponse.setDateHeader("Expires", expiredSinceYesterday(now)); //$NON-NLS-1$
    httpResponse.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
    httpResponse.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
}

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

/**
 *  Header./*w w  w .  ja v  a2s.c  o m*/
 */
public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
    //Http 1.0 header
    response.setDateHeader("Expires", System.currentTimeMillis() + expiresSeconds * 1000);
    //Http 1.1 header
    response.setHeader("Cache-Control", "max-age=" + expiresSeconds);
}