Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 93440 invoked from network); 17 Sep 2007 07:21:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Sep 2007 07:21:15 -0000 Received: (qmail 14907 invoked by uid 500); 17 Sep 2007 07:21:05 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 14834 invoked by uid 500); 17 Sep 2007 07:21:04 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 14825 invoked by uid 99); 17 Sep 2007 07:21:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Sep 2007 00:21:04 -0700 X-ASF-Spam-Status: No, hits=4.1 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WEIRD_PORT,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Sep 2007 07:22:53 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IXAuP-0000nD-D5 for user@commons.apache.org; Mon, 17 Sep 2007 00:20:41 -0700 Message-ID: <12730645.post@talk.nabble.com> Date: Mon, 17 Sep 2007 00:20:41 -0700 (PDT) From: bhadu To: user@commons.apache.org Subject: Uploading a File using apache commons Http clien MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: rajbhadu_reck@rediffmail.com X-Virus-Checked: Checked by ClamAV on apache.org Hi all, sorry for repost b'coz my first post is consists with error... this is right post...... I have to web application using servlets. My First web application's servlet is calling servlet of another application using HTTP client connection. Calling servlet is sending file as parameter to second servlet. My problem is that in my second servlet there is nothing in request parameter. Look at my code...............First servlet........... String urlString = "http://localhost:8787//testone//MyServlet"; HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(urlString); post(postMethod); client.getParams().setParameter("http.useragent", "My Browser"); postMethod.addParameter("test","testvalue"); NameValuePair[] nm = {new NameValuePair("test","test")}; postMethod.setRequestBody(nm); int statusCode1 = client.executeMethod(postMethod); System.out.println(" status >>> "+statusCode1); System.out.println("statusLine>>>" + postMethod.getStatusLine()); postMethod.releaseConnection(); } private void post(PostMethod postMethod) throws FileNotFoundException { File f = new File("C:\\error.txt"); System.out.println("file exit = "+f.exists()); Part[] parts = { new FilePart(f.getName(), f) }; postMethod.addRequestHeader("Content-type","multipart/form-data;boundary="+f.length()); postMethod.addRequestHeader("content-disposition","form-data; name="+f.getName()); postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams()) ); } And This is my Second servlet....................... protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = System.getenv("Target_PATH"); try { DiskFileItemFactory df = new DiskFileItemFactory(); PrintWriter out = response.getWriter(); ServletFileUpload fu = new ServletFileUpload(df); // If file size exceeds, a FileUploadException will be thrown fu.setSizeMax(1000000); List fileItems = fu.parseRequest(request); Iterator itr = fileItems.iterator(); while(itr.hasNext()) { FileItem fi = (FileItem)itr.next(); createFile(path,"signedresources.txt", fi.get()); } out.println("SUCCESS123456: "); out.close(); } catch(Exception e) { e.printStackTrace(); } } private void createFile(String destinationPath, String fileName, byte[] content) throws IOException { OutputStream outputStream = new FileOutputStream(destinationPath); outputStream.write(content); outputStream.flush(); outputStream.close(); } problem is here....... List fileItems = fu.parseRequest(request); list is empty. So anybody can tell me what is wrong I m doing? I am using Tomcat 5.0. Thanx In advance bhadu -- View this message in context: http://www.nabble.com/Uploading-a-File-using-apache-commons-Http-clien-tf4464865.html#a12730645 Sent from the Commons - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org