List of usage examples for javax.servlet.http HttpServletResponse setHeader
public void setHeader(String name, String value);
From source file:com.ewcms.component.rss.web.RssServlet.java
private void initResponseHeader(final HttpServletResponse response, final String encoding) { response.setHeader("Content-Language", "zh-CN"); String fullContentType = XML_TYPE + ";charset=" + encoding; response.setContentType(fullContentType); }
From source file:com.zuoxiaolong.niubi.job.test.http.DownloadFileController.java
@RequestMapping("/download/test.txt") public void downloadTxt(HttpServletResponse response) throws IOException { String fileName = "test.txt"; response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); OutputStream outputStream = response.getOutputStream(); outputStream.write("hello".getBytes()); outputStream.flush();//ww w. ja va 2 s . co m outputStream.close(); }
From source file:de.otto.jsonhome.controller.HtmlController.java
@RequestMapping(value = "/json-home", method = RequestMethod.GET, produces = "text/html") @ResponseBody//from w w w . j a v a2 s.com public ModelAndView getHtmlHomeDocument(final HttpServletRequest request, final HttpServletResponse response) { // home document should be cached: response.setHeader("Cache-Control", "max-age=" + maxAge); response.setHeader("Vary", "Accept"); final Map<String, Object> resources = new HashMap<String, Object>(); resources.put("resources", jsonHomeSource.getJsonHome().getResources().values()); resources.put("contextpath", request.getContextPath()); return new ModelAndView("resources", resources); }
From source file:org.openmrs.module.logmanager.web.view.DocumentXmlView.java
@SuppressWarnings("rawtypes") @Override/* w w w .j av a 2s .c om*/ protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Disable caching response.setHeader("Pragma", "No-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache"); // Get document and filename from model Document document = (Document) model.get(sourceKey); String filename = (String) model.get(filenameKey); if (document != null) { // Set response headers response.setContentType("text/xml"); if (filename != null) response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); // Write document XML to response stream LogManagerUtils.writeDocument(document, response.getWriter()); } else response.getWriter().write("ERROR: Document is null"); }
From source file:com.qualogy.qafe.gwt.server.filter.CORSFilter.java
public void addGWTSpecificHeaders(HttpServletResponse response) { response.setHeader(ResponseHeader.ACCESS_CONTROL_ALLOW_HEADERS.toString(), X_GWT_MODULE_BASE_RESPONSE_HEADER); response.setHeader(ResponseHeader.ACCESS_CONTROL_ALLOW_HEADERS.toString(), X_GWT_PERMUTATION_RESPONSE_HEADER); }
From source file:HelloJapan.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain; charset=Shift_JIS"); PrintWriter out = res.getWriter(); res.setHeader("Content-Language", "ja"); Locale locale = new Locale("ja", ""); DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Japanese:"); out.println("\u4eca\u65e5\u306f\u4e16\u754c"); // Hello World out.println(full.format(new Date())); }
From source file:org.bonitasoft.web.designer.controller.PreviewController.java
/** * Returns fake css file for living app theme.css *///from w w w .j av a 2 s . com @RequestMapping("/preview/page/theme/theme.css") public void serveWidgetAsset(HttpServletResponse response) throws ServletException { response.setHeader("Content-Type", "text/css"); response.setHeader("Content-Disposition", "inline; filename=\"theme.css\""); response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); response.setStatus(HttpStatus.OK.value()); try (PrintWriter writer = response.getWriter()) { writer.println("/**"); writer.println("* Living application theme"); writer.print("*/"); } catch (IOException e) { // fail silently } }
From source file:com.dangdang.ddframe.job.security.WwwAuthFilter.java
private void needAuthenticate(final HttpServletResponse response) { response.setStatus(401);// www. ja va 2 s .co m response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires", 0); response.setHeader("WWW-authenticate", AUTH_PREFIX + "Realm=\"Elastic Job Console Auth\""); }
From source file:com.tce.oauth2.spring.api.filter.CORSFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Authorization, Content-Type"); response.setHeader("Access-Control-Max-Age", "3600"); if (!"OPTIONS".equals(request.getMethod())) { chain.doFilter(req, res);/*from ww w .ja va 2 s.c o m*/ } else { } }
From source file:com.cfitzarl.cfjwed.controller.StatsController.java
/** * This returns a CSV file containing a list of attendants with the following fields: * * <ul>/*from w w w .j a v a2 s . co m*/ * <li>Name</li> * <li>Response</li> * <li>Meal</li> * </ul> * * @param response the response * @throws Exception */ @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/attendants.csv", method = RequestMethod.GET) public void exportAttendantStats(HttpServletResponse response) throws Exception { response.setHeader("Content-Disposition", "attachment; filename=attendants.csv"); response.setContentType("text/csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { // Write out the headers writer.writeNext(new String[] { localizationService.getMessage("attendants.csv.party"), localizationService.getMessage("attendants.csv.name"), localizationService.getMessage("attendants.csv.response"), localizationService.getMessage("attendants.csv.meal") }); List<Attendant> attendants = attendantService.find(); // Sort by invitation name Collections.sort(attendants, ((attendant, t1) -> attendant.getInvitation().getName() .compareTo(t1.getInvitation().getName()))); // Write out data for each attendant for (Attendant attendant : attendants) { String partyName = attendant.getInvitation().getName(); String status = attendant.getResponseStatus().toString(); String meal = (attendant.getMeal() == null) ? "" : attendant.getMeal().getName(); writer.writeNext(new String[] { partyName, attendant.getName(), status, meal }); } } }