List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:alfio.controller.AdminController.java
private static void downloadTicketsCSV(String eventName, String fileName, String[] header, Principal principal, HttpServletResponse response, EventManager eventManager, Function<Ticket, String[]> ticketMapper) throws IOException { Validate.isTrue(StringUtils.isNotBlank(eventName), "Event name is not valid"); List<Ticket> tickets = eventManager.findAllConfirmedTickets(eventName, principal.getName()); response.setContentType("text/csv;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" + eventName + "-" + fileName + ".csv"); try (ServletOutputStream out = response.getOutputStream()) { for (int marker : BOM_MARKERS) {//UGLY-MODE_ON: specify that the file is written in UTF-8 with BOM, thanks to alexr http://stackoverflow.com/a/4192897 out.write(marker);/* www . j a v a 2 s . c om*/ } CSVWriter writer = new CSVWriter(new OutputStreamWriter(out)); writer.writeNext(header); tickets.stream().map(ticketMapper).forEach(writer::writeNext); writer.flush(); out.flush(); } }
From source file:com.sobey.framework.utils.Servlets.java
/** * Header./* w w w . j a va2 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:com.cnksi.core.web.utils.Servlets.java
/** * Header./* w w w. ja v a2 s .co 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:com.ccf.util.ModDateHeaderUtil.java
/** * ??//from ww w. j a v a2 s . c o m * @param response */ public static void setLastModifiedHeader(HttpServletResponse response) { SimpleDateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss"); Calendar lastModifiedCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); String lastModified = df.format(lastModifiedCal.getTime()); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); response.setHeader("Date", df.format(cal.getTime()) + " GMT"); cal.add(Calendar.DAY_OF_MONTH, 1); // response.setHeader("Expires",df.format(cal.getTime())+" GMT"); response.setHeader("Retry-After", df.format(cal.getTime()) + " GMT"); response.setHeader("Cache-Control", "public"); //response.setHeader("Last-Modified",lastModified+" GMT"); response.setDateHeader("Last-Modified", System.currentTimeMillis() - 60 * 60 * 1000); // Force clients to revalidate each time // See RFC 2616 (HTTP 1.1 spec) secs 14.21, 13.2.1 response.setDateHeader("Expires", System.currentTimeMillis() + (expiresOffset * 1000)); // We may also want this (See 13.2.1 and 14.9.4) // response.setHeader("Cache-Control","must-revalidate"); }
From source file:org.artifactory.webapp.servlet.RequestUtils.java
/** * Verifies user agent is Internet Explorer according to: * https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx * https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx * http://www.useragentstring.com/pages/Internet%20Explorer/ * * And adds the compatibility header to avoid explorer defaulting to IE7 mode when launching compatibility view. * see RTFACT-7928/*from www.j av a2 s.c o m*/ */ private static void verifyExplorerUserAgentAndSetHeader(HttpServletRequest request, HttpServletResponse response) { String userAgent = request.getHeader(HttpHeaders.USER_AGENT); if (isNewExplorer(userAgent)) { response.setHeader("X-UA-Compatible", "IE=Edge"); } }
From source file:com.lll.util.ServletUtils.java
/** * Header./*from w w w . j a va 2s .co 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:de.betterform.agent.web.WebUtil.java
public static void nonCachingResponse(HttpServletResponse response) { response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "-1"); }
From source file:lc.kra.servlet.FileManagerServlet.java
private static void downloadFile(HttpServletResponse response, File file, String name, String contentType) throws IOException { response.setContentType(contentType); response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\""); copyStream(new FileInputStream(file), response.getOutputStream()); }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void handlePng(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename) throws IOException { response.setContentType("image/png"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".png\";"); writeImage(response, imageData, width, height, "png"); }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void handleGif(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename) throws IOException { response.setContentType("image/gif"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".gif\";"); writeImage(response, imageData, width, height, "gif"); }