List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:net.mindengine.oculus.frontend.web.controllers.display.FileDisplayController.java
public static void showTextFile(HttpServletResponse response, String path, String fileName, String contentType) throws IOException { OutputStream os = response.getOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); response.setContentType(contentType); response.setCharacterEncoding("UTF-8"); String content = readFileAsString(path); w.write(content);//from ww w .j a v a 2s. c o m w.flush(); os.flush(); os.close(); }
From source file:com.dosport.system.utils.ServletUtils.java
/** * Header.//from w w w .ja va 2 s. c om */ 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", "private, max-age=" + expiresSeconds); }
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
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); }
From source file:com.pactera.edg.am.metamanager.extractor.util.AntZip.java
public static void zipFile(String inputFileName, HttpServletResponse response) { try {/*from ww w. j a va2 s . c o m*/ response.setContentType("text/plain;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=data.zip"); response.setStatus(HttpServletResponse.SC_OK); //?? OutputStream output = response.getOutputStream(); ZipOutputStream zipOut = new ZipOutputStream(output); zip(zipOut, new File(inputFileName), ""); if (zipOut != null) zipOut.close(); if (output != null) output.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { } }
From source file:com.xsw.utils.Servlets.java
/** * ?Header.//from w ww.ja va 2 s . co m */ public static void setNoCacheHeader(HttpServletResponse response) { // Http 1.0 header response.setDateHeader("Expires", 1L); response.addHeader("Pragma", "no-cache"); // Http 1.1 header response.setHeader("Cache-Control", "no-cache, no-store, max-age=0"); }
From source file:cn.com.qiqi.order.utils.Servlets.java
/** * ??Header.// w ww . java 2 s . com * * @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:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java
/** * Get a response Writer depending on acceptable encodings * @param request the servlet's request information * @param response the servlet's response information * @exception IOException an I/O error occurred *//* ww w . j ava 2 s . c o m*/ public static Writer getWriter(HttpServletRequest request, HttpServletResponse response) throws IOException { Writer out; String encodings = request.getHeader("Accept-Encoding"); if (encodings != null && encodings.indexOf("gzip") != -1) { response.setHeader("Content-Encoding", "gzip"); out = new OutputStreamWriter(new GZIPOutputStream(response.getOutputStream()), "UTF-8"); } else if (encodings != null && encodings.indexOf("deflate") != -1) { response.setHeader("Content-Encoding", "deflate"); out = new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"); } else { out = response.getWriter(); } return out; }
From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java
/** * This method returns report information to the AppVet ToolAdapter as ASCII * text and cannot attach a file to the response. *///w w w.j ava 2 s .c o m public static boolean sendInHttpResponse(HttpServletResponse response, String reportText, ToolStatus reportStatus) { try { response.setStatus(HttpServletResponse.SC_OK); // HTTP 200 response.setContentType("text/html"); response.setHeader("toolrisk", reportStatus.name()); PrintWriter out = response.getWriter(); out.println(reportText); out.flush(); out.close(); log.debug("Returned report"); return true; } catch (IOException e) { log.error(e.toString()); return false; } }
From source file:org.openmrs.module.omodexport.util.OmodExportUtil.java
/** * Utility method for exporting a single module * //from w ww .ja v a 2 s .co m * @param module -The module to export * @param response */ public static void exportSingleModule(Module module, HttpServletResponse response) { File file = module.getFile(); response.setContentLength(new Long(file.length()).intValue()); response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); try { FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.wavemaker.runtime.FileController.java
public static void setCacheExpireDate(HttpServletResponse response, int seconds) { if (response != null) { Calendar cal = new GregorianCalendar(); cal.add(Calendar.SECOND, seconds); response.setHeader("Cache-Control", "PUBLIC, max-age=" + seconds + ", must-revalidate"); response.setHeader("Expires", htmlExpiresDateFormat().format(cal.getTime())); }//w w w. j a va 2s . c o m }