List of usage examples for javax.servlet.http HttpServletResponse reset
public void reset();
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
@RequestMapping({ "/exportReport" }) public String exportReport(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset(); response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.financialStatements(workbook, queryMap); workbook.write(os);/*from w w w .j a va 2 s. co m*/ os.flush(); os.close(); return "train/exportReport"; }
From source file:org.sakaiproject.sdata.tool.ControllerServlet.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Handler h = getHandler(request); if (h != null) { h.setHandlerHeaders(request, response); h.doPut(request, response);/*from ww w . j av a2s. c o m*/ } else { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Handler Found"); } }
From source file:org.sakaiproject.sdata.tool.ControllerServlet.java
@Override protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Handler h = getHandler(request); if (h != null) { h.setHandlerHeaders(request, response); h.doHead(request, response);// w w w . j ava 2 s.com } else { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Handler Found"); } }
From source file:org.sakaiproject.sdata.tool.ControllerServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Handler h = getHandler(request); if (h != null) { h.setHandlerHeaders(request, response); h.doPost(request, response);/*w w w.j a v a 2 s . co m*/ } else { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Handler Found"); } }
From source file:org.sakaiproject.sdata.tool.ControllerServlet.java
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Handler h = getHandler(request); if (h != null) { h.setHandlerHeaders(request, response); h.doDelete(request, response);//from w w w. j av a 2s . c o m } else { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Handler Found"); } }
From source file:org.sakaiproject.sdata.tool.ControllerServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Handler h = getHandler(request); if (h != null) { h.setHandlerHeaders(request, response); h.doGet(request, response);/* w w w. j ava 2 s . c om*/ } else { if (!describe(request, response)) { response.reset(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Handler Found"); } } }
From source file:org.ajax4jsf.webapp.BaseXMLFilter.java
/** * @param response/* w w w. j a v a 2 s . c o m*/ * @param servletResponseWrapper * @param ajaxResponseType * @return * @throws IOException * @throws UnsupportedEncodingException */ private Writer resetResponse(final HttpServletResponse response, FilterServletResponseWrapper servletResponseWrapper, String ajaxResponseType) throws IOException, UnsupportedEncodingException { Writer output; response.reset(); // Keep cookies. for (Iterator<Cookie> iter = servletResponseWrapper.getCookies().iterator(); iter.hasNext();) { Cookie cookie = (Cookie) iter.next(); response.addCookie(cookie); } // Copy response headers Map<String, Object> headers = servletResponseWrapper.getHeaders(); for (Iterator<Map.Entry<String, Object>> iter = headers.entrySet().iterator(); iter.hasNext();) { Map.Entry<String, Object> header = iter.next(); response.setHeader((String) header.getKey(), (String) header.getValue()); } response.setHeader(AjaxContainerRenderer.AJAX_FLAG_HEADER, ajaxResponseType); // Not caching AJAX request response.setHeader("Cache-Control", "no-cache, must-revalidate, max_age=0, no-store"); response.setHeader("Expires", "0"); response.setHeader("Pragma", "no-cache"); response.setContentType(getMimetype() + ";charset=UTF-8"); output = createOutputWriter(response, "UTF-8"); return output; }
From source file:com.athena.chameleon.web.common.controller.FileController.java
@RequestMapping("/download.do") public void download(HttpServletRequest request, HttpServletResponse response, @RequestParam("path") String path) throws Exception { Assert.notNull(path, "name must not be null."); File file = new File(path); Assert.isTrue(file.exists(), path + " does not exist."); String name = path.replaceAll("\\\\", "/"); name = name.substring(name.lastIndexOf("/") + 1, name.length()); long fileSize = file.length(); if (fileSize > 0L) { response.setHeader("Content-Length", Long.toString(fileSize)); }//w w w . j av a 2 s .c o m String fileExt = name.substring(name.lastIndexOf(".") + 1); response.reset(); if (fileExt.equals("pdf")) { response.setContentType("application/pdf"); } else if (fileExt.equals("zip")) { response.setContentType("application/zip"); } else if (fileExt.equals("ear")) { response.setContentType("application/zip"); } else if (fileExt.equals("war")) { response.setContentType("application/zip"); } else if (fileExt.equals("jar")) { response.setContentType("application/zip"); } else { response.setContentType("application/octet-stream"); } if (request.getHeader("User-Agent").toLowerCase().contains("firefox") || request.getHeader("User-Agent").toLowerCase().contains("safari")) { response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(name.getBytes("UTF-8"), "ISO-8859-1") + "\""); response.setHeader("Content-Transfer-Encoding", "binary"); } else { response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8")); } try { BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file)); BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream()); int read = 0; while ((read = fin.read()) != -1) { outs.write(read); } IOUtils.closeQuietly(fin); IOUtils.closeQuietly(outs); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.orderofthebee.addons.support.tools.share.LogFileHandler.java
protected void handleLogFileRequest(final String filePath, final boolean attach, final HttpServletRequest req, final HttpServletResponse res, final Map<String, Object> model) throws IOException { try {// w ww. j a v a 2 s .co m final File file = validateFilePath(filePath); final String mimetype = determineMimetypeFromFileName(file); this.contentStreamer.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model, mimetype); } catch (final WebScriptException wsex) { if (!res.isCommitted()) { res.reset(); res.sendError(wsex.getStatus(), wsex.getMessage()); } else { LOGGER.info("Could not send error via committed response", wsex); } } }
From source file:org.ngrinder.script.controller.FileEntryController.java
/** * Download file entry of given path./*from w ww . j a v a2 s . co m*/ * * @param user current user * @param path user * @param response response */ @RequestMapping("/download/**") public void download(User user, @RemainedPath String path, HttpServletResponse response) { FileEntry fileEntry = fileEntryService.getOne(user, path); if (fileEntry == null) { LOG.error("{} requested to download not existing file entity {}", user.getUserId(), path); return; } response.reset(); try { response.addHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(FilenameUtils.getName(fileEntry.getPath()), "utf8")); } catch (UnsupportedEncodingException e1) { LOG.error(e1.getMessage(), e1); } response.setContentType("application/octet-stream; charset=UTF-8"); response.addHeader("Content-Length", "" + fileEntry.getFileSize()); byte[] buffer = new byte[4096]; ByteArrayInputStream fis = null; OutputStream toClient = null; try { fis = new ByteArrayInputStream(fileEntry.getContentBytes()); toClient = new BufferedOutputStream(response.getOutputStream()); int readLength; while (((readLength = fis.read(buffer)) != -1)) { toClient.write(buffer, 0, readLength); } } catch (IOException e) { throw processException("error while download file", e); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(toClient); } }