Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 83381 invoked from network); 28 Aug 2008 13:28:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Aug 2008 13:28:37 -0000 Received: (qmail 91885 invoked by uid 500); 28 Aug 2008 13:28:34 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 91815 invoked by uid 500); 28 Aug 2008 13:28:34 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 91804 invoked by uid 99); 28 Aug 2008 13:28:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2008 06:28:33 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2008 13:27:44 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id BE91A234C1B5 for ; Thu, 28 Aug 2008 06:27:44 -0700 (PDT) Message-ID: <1159861555.1219930064779.JavaMail.jira@brutus> Date: Thu, 28 Aug 2008 06:27:44 -0700 (PDT) From: "Barry Barrios (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (FILEUPLOAD-165) Reading an uploaded file and returning that uploaded file in the exact same structure as the input file In-Reply-To: <1162630460.1219927065204.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/FILEUPLOAD-165?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12626557#action_12626557 ] Barry Barrios commented on FILEUPLOAD-165: ------------------------------------------ Dear Jochen, Last question I promise, Yeah I was thinking about that but I was confused about two things: replacing this line response.getWriter().write(new String(uploadItem.get())); with 1) response.getOutputStream().println(new String(uploadItem.get())); (with no carriage return-line feed (CRLF) at the end.) or 2) response.getOutputStream().print(new String(uploadItem.get())); (Writes a String to the client, followed by a carriage return-line feed (CRLF).) what is a carriage return-line feed(CRLF)? My input data is like this,i.e: 1 2 "305 Memorial Drive Cambridge, Ma,02139" 3 4 "77 Massachusetts Ave, Cambridge MA, 02139" and I want my output to look like: 1 2 "305 Memorial Drive Cambridge, Ma,02139" 3 4 "77 Massachusetts Ave, Cambridge MA, 02139" well at the end I am going to change the output, this is just to see how it works. I wasn't sure what the difference is bet. print and println or what is CRLF. Your attention to this matter is highly appreciated. Sincerely, Barry Barrios > Reading an uploaded file and returning that uploaded file in the exact same structure as the input file > ------------------------------------------------------------------------------------------------------- > > Key: FILEUPLOAD-165 > URL: https://issues.apache.org/jira/browse/FILEUPLOAD-165 > Project: Commons FileUpload > Issue Type: Task > Affects Versions: 1.2 > Environment: Windows XP Professional > Reporter: Barry Barrios > Assignee: Jochen Wiedmann > Priority: Critical > Fix For: 1.2.1 > > Original Estimate: 1h > Remaining Estimate: 1h > > I am using response.getWriter().write(new String(uploadItem.get() to write the uploaded input file. The code works pretty well except the output is very disorganized. I want the output to look exactly the same as the input file, in structure, the same space, the same columns, a perfect copy. However the output file, is scrammbled all together. What can be done to alter this code so that the input file looks like the output file. > Sample Code Below: > package de.herbstcampus.server; > import java.io.IOException; > import java.util.List; > import javax.servlet.ServletException; > import javax.servlet.http.HttpServlet; > import javax.servlet.http.HttpServletRequest; > import javax.servlet.http.HttpServletResponse; > import org.apache.commons.fileupload.FileItem; > import org.apache.commons.fileupload.FileItemFactory; > import org.apache.commons.fileupload.FileUploadException; > import org.apache.commons.fileupload.disk.DiskFileItemFactory; > import org.apache.commons.fileupload.servlet.ServletFileUpload; > public class FileUploadServlet extends HttpServlet { > private static final long serialVersionUID = 1156467149259077140L; > protected void doPost(HttpServletRequest request, > HttpServletResponse response) throws ServletException, IOException { > FileItem uploadItem = getFileItem(request); > > /* > * Note this must be 'text/html', otherwise the onSubmitComplete(...) > * won't work properly and the browser may open a save dialog. > */ > response.setContentType("text/html"); > > if (uploadItem == null) { > response.getWriter().write("No data"); > return; > } else { > response.getWriter().write(new String(uploadItem.get())); > } > } > @SuppressWarnings("unchecked") > private FileItem getFileItem(HttpServletRequest request) { > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > try { > List items = upload.parseRequest(request); > > for (FileItem item: items) { > if (!item.isFormField() > && "uploadFormElement".equals(item.getFieldName())) { > return item; > } > } > } catch (FileUploadException e) { > return null; > } > > return null; > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.