List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:com.eryansky.common.web.utils.WebUtils.java
/** * ??Header.//w w w .java 2 s . c om * * @param fileName * ???. */ public static void setDownloadableHeader(HttpServletResponse response, String fileName) { response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); }
From source file:com.eryansky.common.web.utils.WebUtils.java
/** * Gzip HeaderGZIPOutputStream.//from w ww . j ava 2 s. c om */ public static OutputStream buildGzipOutputStream(HttpServletResponse response) throws IOException { response.setHeader("Content-Encoding", "gzip"); response.setHeader("Vary", "Accept-Encoding"); return new GZIPOutputStream(response.getOutputStream()); }
From source file:com.lily.dap.web.util.WebUtils.java
/** * Gzip HeaderGZIPOutputStream.//from w w w . j a v a2s . c om */ public static OutputStream buildGzipOutputStream(HttpServletResponse response) throws IOException { response.setHeader("Content-Encoding", "gzip"); return new GZIPOutputStream(response.getOutputStream()); }
From source file:com.dosport.system.utils.ServletUtils.java
/** * Etag Header.// w w w .j a va 2s .c om */ public static void setEtag(HttpServletResponse response, String etag) { response.setHeader("ETag", etag); }
From source file:net.sf.ehcache.constructs.web.ResponseUtil.java
/** * Adds the gzip HTTP header to the response. This is need when a gzipped body is returned so that browsers can properly decompress it. * <p/>//from w w w . j a v a 2s.com * @param response the response which will have a header added to it. I.e this method changes its parameter * @throws ResponseHeadersNotModifiableException Either the response is committed or we were called using the include method * from a {@link javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)} * method and the set set header is ignored. */ public static void addGzipHeader(final HttpServletResponse response) throws ResponseHeadersNotModifiableException { response.setHeader("Content-Encoding", "gzip"); boolean containsEncoding = response.containsHeader("Content-Encoding"); if (!containsEncoding) { throw new ResponseHeadersNotModifiableException( "Failure when attempting to set " + "Content-Encoding: gzip"); } }
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
public static void setEtag(HttpServletResponse response, String etag) { response.setHeader("ETag", etag); }
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 ww w . j a v a 2 s .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.handpay.ibenefit.framework.util.WebUtils.java
public static void setDownloadableHeader(HttpServletResponse response, String fileName) { response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); }
From source file:gov.nih.nci.caintegrator.application.util.CSVUtil.java
public static void renderCSV(HttpServletResponse response, List<List> csv) { PrintWriter out = null;/*from ww w . j av a2 s . com*/ long randomness = System.currentTimeMillis(); response.setContentType("application/csv"); response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv"); try { for (List row : csv) { out = response.getWriter(); out.write(StringUtils.join(row.toArray(), ",") + "\r\n"); out.flush(); } } catch (Exception e) { out.write("error generating report"); } }
From source file:com.manydesigns.elements.servlet.ServletUtils.java
/** * Marks the resource returned to a web client to be stored in cache for a very long time. * The resource is marked to be cached privately, i.e. on the client only, not in intermediate caches like proxies. * @param response the HTTP response whose headers are set. *//*from w w w . jav a 2 s . com*/ public static void markCacheableForever(HttpServletResponse response) { long expiresAfterMillis = System.currentTimeMillis() + ONE_YEAR_MILLIS; response.setHeader(ServletConstants.HTTP_PRAGMA, ""); response.setDateHeader(ServletConstants.HTTP_EXPIRES, expiresAfterMillis); //Private - only authorized users can cache the content response.setHeader(ServletConstants.HTTP_CACHE_CONTROL, ServletConstants.HTTP_CACHE_CONTROL_PRIVATE); response.addHeader(ServletConstants.HTTP_CACHE_CONTROL, ServletConstants.HTTP_CACHE_CONTROL_MAX_AGE + ONE_YEAR_MILLIS); }