Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 34221 invoked from network); 17 Jul 2007 13:47:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Jul 2007 13:47:39 -0000 Received: (qmail 52293 invoked by uid 500); 17 Jul 2007 13:47:37 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 52162 invoked by uid 500); 17 Jul 2007 13:47:37 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 52001 invoked by uid 99); 17 Jul 2007 13:47:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jul 2007 06:47:36 -0700 X-ASF-Spam-Status: No, hits=2.1 required=10.0 tests=HTML_MESSAGE,HTML_TAG_EXIST_TBODY,MANY_EXCLAMATIONS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [209.191.85.39] (HELO web36705.mail.mud.yahoo.com) (209.191.85.39) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 17 Jul 2007 06:47:29 -0700 Received: (qmail 42834 invoked by uid 60001); 17 Jul 2007 13:47:08 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=ag2Vgjh+p4LCLHsNAIu3WDX7Q8Wt+nudLSfjW3lOMGQ2zrkiU9RcAVVlstCBSJuZ9yYkedkaZf2Gi6esonfSFioXfesZ8i+FSERwC0W3FA1a2Yean4DMosqIS5ozjDU92Kbb0vJRIHTuinlAqWrPoAvev3dWPgWQ1+SQxogY6cw=; X-YMail-OSG: DCNboOUVM1kF5u2tSD7c0Fmrx5yAv6_H1fU0jCraPOq53_pmLyXuNkcuIUg4KG7yaPzHakO8lZzpsYRDGx4cKa3wAhGrNpgSHUe3vk_w5sN8UWuX2psqFuba78k_Sw-- Received: from [204.69.40.13] by web36705.mail.mud.yahoo.com via HTTP; Tue, 17 Jul 2007 06:47:08 PDT Date: Tue, 17 Jul 2007 06:47:08 -0700 (PDT) From: Bibs L Subject: Help! Download .CSV file using SurvletResponse, it added unwanted characters in the end of the file!! To: Jakarta Commons Developers List In-Reply-To: <31cc37360707161406i437c5a7amdad81c1d08ae0f78@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1035597200-1184680028=:41780" Content-Transfer-Encoding: 8bit Message-ID: <164350.41780.qm@web36705.mail.mud.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org --0-1035597200-1184680028=:41780 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi, I need some help woth downloading .CSV file with the regular ServletResponseObject, it is adding unwanted characters (2 boxes) in the end of the file when I download it. Your help would be greatly appreciated! I have a download.jsp file, that calls a manage bean downloadfile.java to render a file, it is all working well with the excaption of downloading .CSV file. The problem is that when I try to download a CSV file, by clickin on the link, thats calls the Download.java bean which set the Response object, and opens up the "Download File Diaglog - Open/Save As", when I open/save as the CSV file, it added unwanted characters at the very bottom of the file. Even when I tested to upload a totally empty file, when I download it, it added the unwanted characters (2 Boxes) , where it should have been empty. Orignally, I have the ..etc tags on the download.jsp, and all of those HTML code were added to the end of the CSV file in addition to the unwanted file. So, I removed all of the unnesscary tags, and the HTML codes are gone from the CSV file, but the unwanted characters are still being added at the end of the file. I have no idea how it got there. PLEASE HELP! --------------------------------------------------- Download.jsp: <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ page import="java.util.ResourceBundle" %> <%@ page import="com......bean.DownloadFileBean" %> <% javax.faces.context.FacesContext facesContext = null; ResourceBundle messages = ResourceBundle.getBundle("com......nl.ErrorMessages"); LogServices LOG = LogServicesFactory.getInstance().createLogServices(DownloadFileBean.class); try{ //get an instance from faceContext facesContext = javax.faces.context.FacesContext.getCurrentInstance(); DownloadFileBean downloadFileBean = (DownloadFileBean)facesContext.getApplication().getVariableResolver().resolveVariable(facesContext, "downloadFileBean"); String result = downloadFileBean.DownloadFile(); } catch (Exception e) { LOG.error("Exception : RenderFile.jsp - " + e.getMessage(), e); } finally { if (facesContext != null) facesContext = null; } %> --------------------------------------------------- DownloadFile.Java: public boolean DownloadFile (){ boolean result = false; FacesContext faces = null; HttpServletResponse response = null; File file = null; FileInputStream fileIn = null; ServletOutputStream output = null; try{ MyFileBean myFileBean = (MyFileBean)getBean("myFileBean"); String fileName = myFileBean.getRenderingFileName(); String filePath = myFileBean.getRenderingFilePath(); String fileFullPath = myFileBean.getRenderingFilePath() + fileName; LOG.debug("file full path = " + fileFullPath); if (fileFullPath == null) { LOG.debug("file path is null..."); return result; } file = new File(fileFullPath); if(file.exists() == false){ LOG.debug(fileName + " - file not found..."); return result; } faces = FacesContext.getCurrentInstance(); response = (HttpServletResponse) faces.getExternalContext().getResponse(); long startTime = System.currentTimeMillis(); fileIn = new FileInputStream(file); output = response.getOutputStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition","attachment; filename=\"" + file.getName() + "\""); IOUtils.copy(fileIn, output); output.flush(); faces.responseComplete(); long endTime = System.currentTimeMillis(); result = true; LOG.debug("Total Time Taken to download: "+(endTime - startTime) + " ms"); } catch (FileNotFoundException e) { LOG.error("FileNotFoundException : DownloadFileBean.java - " + e.getMessage(), e); } catch (IOException e) { LOG.error("IOException : DownloadFileBean.java - " + e.getMessage(), e); } catch (Exception e) { LOG.error("Exception : DownloadFileBean.java - " + e.getMessage(), e); } finally { //Close output and input resources. try { if (faces != null) faces = null; if (response != null) response = null; if (file != null) file = null; if (output != null) output.close(); } catch (Exception e) { LOG.error("Exception : DownloadFileBean.java - Closing objects " + e.getMessage(), e); } } LOG.debug(">>>END - DownloadFileBean : downloadFile "); return result; } ---------------------------------------------------------- Unwanted Code added to CSV File: (Used to be like this before I removed all the HTML tags from Download.jsp) Render File
4 unwanted boxes...
---------------------------------------------------------- Unwanted Code added to CSV File: (after I removed all the HTML tags from Download.jsp) 2 boxes (I can't copy and pasted the unwanted boxes into the email.) --------------------------------- Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. --0-1035597200-1184680028=:41780--