List of usage examples for javax.servlet.http HttpServletResponse reset
public void reset();
From source file:com.glaf.oa.reports.web.springmvc.OAReportController.java
public static void exportExcel(String fileName, String targetName, Map<String, Object> datas, HttpServletResponse response) { fileName = SystemProperties.getAppPath() + "/WEB-INF/conf/templates/oa/" + fileName + ".xls"; XLSTransformer transformer = new XLSTransformer(); FileInputStream fis = null;//from w w w . j a v a 2s . c o m OutputStream os = null; Workbook workbook = null; try { fis = new FileInputStream(fileName); workbook = transformer.transformXLS(fis, datas); response.reset(); response.setHeader("content-disposition", "attachment; filename=" + targetName + ".xls"); response.setContentType("application/msexcel"); os = response.getOutputStream(); if (os != null) { workbook.write(os); } } catch (FileNotFoundException e) { logger.error("exportExcel:" + e.getMessage()); } catch (ParsePropertyException e) { logger.error("exportExcel:" + e.getMessage()); } catch (InvalidFormatException e) { logger.error("exportExcel:" + e.getMessage()); } catch (IOException e) { logger.error("exportExcel:" + e.getMessage()); } finally { try { if (fis != null) fis.close(); if (os != null) { os.flush(); os.close(); } } catch (IOException e) { logger.debug("exportExcel:" + e.getMessage()); } } }
From source file:org.jbpm.formModeler.service.bb.mvc.controller.responses.SendStreamResponse.java
public boolean execute(CommandRequest cmdReq) throws Exception { if (log.isDebugEnabled()) log.debug("SendStreamResponse"); HttpServletResponse res = cmdReq.getResponseObject(); if (errorCode != 0) { res.sendError(errorCode);//from www. j a v a 2s .c o m return false; } if (resetHeaders) res.reset(); //Remove everything, including headers. The stream is often a file that may be cached. res.setHeader("Content-Encoding", HTTPSettings.lookup().getEncoding()); if (contentDisposition != null) { res.setHeader("Content-Disposition", contentDisposition); log.debug("Content-Disposition = " + contentDisposition); } if (contentType != null) res.setContentType(contentType); res.setHeader("Content-Transfer-Encoding", "binary"); if (contentLength < 0) contentLength = is.available(); if (contentLength > 0) { res.setContentLength(contentLength); log.debug("Content-Length = " + contentLength); } try { OutputStream os = new BufferedOutputStream(cmdReq.getResponseObject().getOutputStream()); IOUtils.copy(is, os); os.close(); is.close(); } catch (Exception e) { log.warn("Error sending Stream Response: " + e); //res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return false; } return true; }
From source file:fll.web.api.JudgesServlet.java
@SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Dynamic table based upon categories") @Override/* ww w. j a v a 2 s.co m*/ protected final void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final ObjectMapper jsonMapper = new ObjectMapper(); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); final ServletContext application = getServletContext(); int numNewJudges = 0; final DataSource datasource = ApplicationAttributes.getDataSource(application); Connection connection = null; PreparedStatement insertJudge = null; try { connection = datasource.getConnection(); final int currentTournament = Queries.getCurrentTournament(connection); final StringWriter debugWriter = new StringWriter(); IOUtils.copy(request.getReader(), debugWriter); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Read data: " + debugWriter.toString()); } final Reader reader = new StringReader(debugWriter.toString()); final Collection<JudgeInformation> judges = jsonMapper.readValue(reader, JudgesTypeInformation.INSTANCE); final Collection<JudgeInformation> currentJudges = JudgeInformation.getJudges(connection, currentTournament); insertJudge = connection .prepareStatement("INSERT INTO Judges (id, category, Tournament, station) VALUES (?, ?, ?, ?)"); insertJudge.setInt(3, currentTournament); for (final JudgeInformation judge : judges) { if (null != judge) { JudgeInformation found = null; for (final JudgeInformation cjudge : currentJudges) { if (ComparisonUtils.safeEquals(cjudge, judge)) { found = cjudge; } } if (null == found) { insertJudge.setString(1, judge.getId()); insertJudge.setString(2, judge.getCategory()); insertJudge.setString(4, judge.getGroup()); insertJudge.executeUpdate(); ++numNewJudges; } } // non-null judge } // foreach judge sent final UploadResult result = new UploadResult(true, "Successfully uploaded judges", numNewJudges); response.reset(); jsonMapper.writeValue(writer, result); } catch (final SQLException e) { LOGGER.error("Error uploading judges", e); final UploadResult result = new UploadResult(false, e.getMessage(), numNewJudges); jsonMapper.writeValue(writer, result); } finally { SQLFunctions.close(insertJudge); SQLFunctions.close(connection); } }
From source file:com.byd.test.actions.OrderAction.java
License:asdf
@RequestMapping("xopera") public ModelAndView xopera(HttpServletRequest request, HttpServletResponse response) { try {//from w w w.java 2s . c om OutputStream out = response.getOutputStream(); response.reset(); response.setHeader("content-disposition", "attachment;filename=" + "fileName.xls"); response.setContentType("application/x-octetstream;charset=gb2312"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = null; String sheetName = "first sheet"; sheet = workbook.createSheet(sheetName); System.out.println("*-*-----------------------"); HSSFCell cell = sheet.createRow(1).createCell((short) 2); cell.setCellValue(323); workbook.write(out); out.flush(); out.close(); } catch (IOException ex) { Logger.getLogger(OrderAction.class.getName()).log(Level.SEVERE, null, ex); } String s = (String) request.getParameter("plantCode");//String a = request.getQueryString(""); System.out.println("plantCode: " + s); return new ModelAndView("myname"); }
From source file:Buffering.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(8 * 1024); // 8K res.setContentType("text/html"); PrintWriter out = res.getWriter(); int size = res.getBufferSize(); // returns 8096 or greater log("The default buffer size is " + size); out.println("The client won't see this"); res.reset(); out.println("Nor will the client see this!"); res.reset();/*from ww w . ja v a 2s . c om*/ out.println("And this won't be seen if sendError() is called"); if (req.getParameter("param") == null) { res.sendError(res.SC_BAD_REQUEST, "param needed"); } }
From source file:action.ImageResult.java
public void execute(ActionInvocation invocation) throws IOException { ImageAction action = (ImageAction) invocation.getAction(); HttpServletResponse response = ServletActionContext.getResponse(); ServletOutputStream sos = response.getOutputStream(); BufferedOutputStream output = null; byte[] imgBytes = action.getCustomImageInBytes(); System.out.println("imgBytes--->" + imgBytes.toString()); response.reset(); response.setBufferSize(10240);//from w w w .j av a 2 s . c o m response.setContentType("image/png"); response.setContentLength(action.getCustomImageInBytes().length); response.setHeader("Content-Disposition", "inline; filename=\"sss\""); //response.getOutputStream().write(action.getCustomImageInBytes()); // response.getOutputStream().flush(); try { output = new BufferedOutputStream(response.getOutputStream(), 10240); output.write(imgBytes); } finally { // Gently close streams. if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.sshdemo.common.report.manage.web.ParameterSetAction.java
private void buildText() { PrintWriter pw = null;//from w ww.j a v a 2s.c o m InputStream in = null; try { TextReport report = reportFac.findTextReportById(reportId); HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); pw = response.getWriter(); response.reset();// response.setContentLength(0); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); byte[] bytes = textFactory.export(paraMap, report, fileFormat, response, request); in = new ByteArrayInputStream(bytes); int len = 0; while ((len = in.read()) > -1) { pw.write(len); } pw.flush(); } catch (Exception e) { // log.error(e.toString()); } finally { if (pw != null) { try { pw.close(); pw = null; } catch (Exception e) { } } if (in != null) { try { in.close(); in = null; } catch (Exception e) { } } } }
From source file:org.sakaiproject.signup.tool.downloadEvents.DownloadEventBean.java
private void responseSettings(String filename, String mimetype, HttpServletResponse response) { // Stop IE from misbehaving response.reset(); // Eliminate the added-on stuff response.setHeader("Pragma", "public"); // Override old-style cache // control/* ww w .j ava 2 s . co m*/ response.setHeader("Cache-Control", "public, must-revalidate, post-check=0, pre-check=0, max-age=0"); // New-style // Standard headers response.setContentType(mimetype); response.setHeader("Content-disposition", "attachment; filename=" + filename); }
From source file:in.arun.faces.fo.pdf.FoOutputStream.java
@Override public void close() throws IOException { if (closed) { throw new IOException("Stream has already been closed"); }/*from ww w . j a v a2 s . com*/ closed = true; PdfResult result = buildPdf(this); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); response.reset(); String fileName; if (null == (fileName = request.getParameter("output"))) { fileName = FilenameUtils.getBaseName(request.getRequestURL().toString()); } fileName += ".pdf"; response.setContentType(result.contentType); response.setContentLength(result.content.length); response.setHeader("content-disposition", "inline; FileName=\"" + fileName + "\""); OutputStream outputStream = response.getOutputStream(); outputStream.write(result.content); outputStream.flush(); context.responseComplete(); }
From source file:com.pavikumbhar.javaheart.controller.FileUploadController.java
@RequestMapping(value = "/download", method = RequestMethod.GET) public void download(@RequestParam("name") String name, final HttpServletRequest request, final HttpServletResponse response) { System.out.println("name : {}" + name); File file = new File("/app/" + name); System.out.println("Write response..."); try (InputStream fileInputStream = new FileInputStream(file); OutputStream output = response.getOutputStream();) { response.reset(); response.setContentType("application/octet-stream"); response.setContentLength((int) (file.length())); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); IOUtils.copyLarge(fileInputStream, output); output.flush();// w w w . j a va2s.c om } catch (IOException e) { System.out.println(e.getMessage()); } }