List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:com.hzc.framework.ssh.controller.WebUtil.java
public static void writeExcel(String templateFile, String fileName, List list) throws IOException { HttpServletResponse resp = W.getResp(); resp.setContentType("application/vnd.ms-excel"); resp.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".xls" + "\""); new ExcelUtil().writeExcel(templateFile, list, resp.getOutputStream()); }
From source file:edu.unc.lib.dl.admin.controller.ExportController.java
@RequestMapping(value = "{pid}", method = RequestMethod.GET) public void export(@PathVariable("pid") String pid, HttpServletRequest request, HttpServletResponse response) throws IOException { String filename = pid.replace(":", "_") + ".csv"; response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.addHeader("Content-Type", "text/csv"); SearchRequest searchRequest = generateSearchRequest(request, searchStateFactory.createSearchState()); SearchState searchState = searchRequest.getSearchState(); searchState.setResultFields(Arrays.asList(SearchFieldKeys.ID.name(), SearchFieldKeys.TITLE.name(), SearchFieldKeys.RESOURCE_TYPE.name(), SearchFieldKeys.ANCESTOR_IDS.name(), SearchFieldKeys.STATUS.name(), SearchFieldKeys.DATASTREAM.name(), SearchFieldKeys.ANCESTOR_PATH.name(), SearchFieldKeys.CONTENT_MODEL.name(), SearchFieldKeys.DATE_ADDED.name(), SearchFieldKeys.DATE_UPDATED.name(), SearchFieldKeys.LABEL.name())); searchState.setSortType("export"); searchState.setRowsPerPage(searchSettings.maxPerPage); BriefObjectMetadata container = queryLayer.addSelectedContainer(pid, searchState, false); SearchResultResponse resultResponse = queryLayer.getSearchResults(searchRequest); List<BriefObjectMetadata> objects = resultResponse.getResultList(); objects.add(0, container);/* w w w. j ava 2 s . com*/ queryLayer.getChildrenCounts(objects, searchRequest); try (ServletOutputStream out = response.getOutputStream()) { Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1)); try (CSVPrinter printer = CSVFormat.EXCEL.print(writer)) { printHeaders(printer); for (BriefObjectMetadata object : objects) { printObject(printer, object); } } } }
From source file:net.groupbuy.controller.admin.CommonController.java
/** * ??//from ww w. jav a2 s. co m */ @RequestMapping("/unauthorized") public String unauthorized(HttpServletRequest request, HttpServletResponse response) { String requestType = request.getHeader("X-Requested-With"); if (requestType != null && requestType.equalsIgnoreCase("XMLHttpRequest")) { response.addHeader("loginStatus", "unauthorized"); try { response.sendError(HttpServletResponse.SC_FORBIDDEN); } catch (IOException e) { e.printStackTrace(); } return null; } return "/admin/common/unauthorized"; }
From source file:com.eufar.emc.server.UploadFunction.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("UploadFunction - the function started"); response.setContentType("text/html;charset=UTF-8"); response.addHeader("Cache-Control", "no-cache,no-store"); @SuppressWarnings("unused") boolean isMultipart = ServletFileUpload.isMultipartContent(request); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try {//from www . j av a2 s . c o m List<?> items = upload.parseRequest(request); Iterator<?> iter = items.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj == null) { continue; } org.apache.commons.fileupload.FileItem item = (org.apache.commons.fileupload.FileItem) obj; if (FilenameUtils.getExtension(item.getName()).matches("(xml|XML)")) { if (item.isFormField()) { String name = item.getName(); String value = ""; if (name.compareTo("textBoxFormElement") == 0) { value = item.getString(); } else { value = item.getString(); } response.getWriter().write(name + "=" + value + "\n"); } else { byte[] fileContents = item.get(); String message = new String(fileContents); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.getWriter().write(message); System.out.println("UploadFunction - file uploaded"); } } else { System.out.println("UploadFunction - file rejected: wrong format"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.getWriter().write("format"); } } } catch (Exception ex) { System.out.println("UploadFunction - a problem occured: " + ex); response.getWriter().write("ERROR:" + ex.getMessage()); } }
From source file:org.openmrs.module.dhisreport.web.controller.ReportDefinitionController.java
@RequestMapping(value = "/module/dhisreport/exportReportDefinitions", method = RequestMethod.GET) public void export(ModelMap model, HttpServletResponse response) throws Exception { response.setContentType("application/xml"); response.setCharacterEncoding("UTF-8"); response.addHeader("Content-Disposition", "attachment; filename=reportDefinition.xml"); DHIS2ReportingService service = Context.getService(DHIS2ReportingService.class); ReportTemplates templates = service.getReportTemplates(); service.marshallReportTemplates(response.getOutputStream(), templates); }
From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java
private void initResponseHeader(final HttpServletResponse response) { response.setHeader("Content-Language", "zh-CN"); response.setHeader("Cache-Control", "no-store"); //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"); response.setContentType(IMG_JPEG_TYPE); }
From source file:be.fedict.eid.applet.service.HSTSFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { TransportService transportService = this.transportServiceLocator.locateService(); if (null == transportService) { chain.doFilter(request, response); return;//from w w w .jav a 2 s . c om } StrictTransportSecurityConfig hstsConfig = transportService.getStrictTransportSecurityConfig(); if (null == hstsConfig) { chain.doFilter(request, response); return; } LOG.debug("adding HSTS header"); HttpServletResponse httpServletResponse = (HttpServletResponse) response; String headerValue = "max-age=" + hstsConfig.getMaxAge(); if (hstsConfig.isIncludeSubdomains()) { headerValue += "; includeSubdomains"; } httpServletResponse.addHeader("Strict-Transport-Security", headerValue); chain.doFilter(request, response); }
From source file:com.hmsinc.epicenter.webapp.map.MapStylingController.java
@Transactional(readOnly = true) @RequestMapping("/spatial-scan") public void handleSpatialScanRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final StyleParameters styleParameters = parse(request); response.setContentType(PNG_CONTENT_TYPE); response.addHeader("cache-control", "must-revalidate"); final BufferedImage image = spatialScanService.scan(styleParameters.getParameters(), styleParameters.getGeographyClass(), GoogleProjection.GOOGLE_MERCATOR, 800, 600, false, false) .getImage();/* w ww. j a v a2s . com*/ if (image == null) { logger.debug("No image to render: {}", styleParameters); } else { ImageIO.write(image, "png", response.getOutputStream()); } }
From source file:com.intel.rsa.podm.rest.filters.UrlValidationFilter.java
private void setErrorResponse(HttpServletResponse httpServletResponse, ErrorResponse error) { httpServletResponse.reset();/*www.ja v a2 s. co m*/ httpServletResponse.resetBuffer(); //we have to add since this request is outside our app httpServletResponse.addHeader("OData-Version", "4.0"); httpServletResponse.addHeader("Cache-Control", "max-age=0"); httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.setCharacterEncoding(DEFAULT_ENCODING_HTTP); httpServletResponse.setContentType(MediaType.APPLICATION_JSON); httpServletResponse.setStatus(error.getErrorCode()); try (PrintWriter responseWriter = httpServletResponse.getWriter()) { responseWriter.print(getJsonResponse(error)); responseWriter.flush(); } catch (IOException e) { logger.e("Unable to write response. Sending empty body response.", e); } }
From source file:eu.europeana.corelib.europeanastatic.controllers.ImageController.java
private void setImageCacheControlHeaders(HttpServletResponse response) { long now = System.currentTimeMillis(); response.addHeader("Cache-Control", "max-age=" + CACHE_DURATION_IN_SECOND); response.addHeader("Cache-Control", "must-revalidate"); //optional response.setDateHeader("Last-Modified", now); response.setDateHeader("Expires", now + CACHE_DURATION_IN_SECOND * 1000); }