Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 49512 invoked from network); 1 Jun 2009 05:55:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Jun 2009 05:55:36 -0000 Received: (qmail 33684 invoked by uid 500); 1 Jun 2009 05:55:45 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 33605 invoked by uid 500); 1 Jun 2009 05:55:45 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 33594 invoked by uid 99); 1 Jun 2009 05:55:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jun 2009 05:55:45 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of aoingl@gmail.com designates 209.85.198.243 as permitted sender) Received: from [209.85.198.243] (HELO rv-out-0708.google.com) (209.85.198.243) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jun 2009 05:55:36 +0000 Received: by rv-out-0708.google.com with SMTP id k29so2289179rvb.24 for ; Sun, 31 May 2009 22:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=f0j6kdSMW55M+6sQ2JttMiJwVIqvGuX2WTsh1zJWq44=; b=q/fW07jUTyPho7rFaDsoOLvQyYwPnzZ6OPHjCefKeH6F49fJl5w1lrco41GDMupFZW TdTBQAWfvi6RPHID4BZpUx+YUTrs2mVCKLiW1dfzYA58jSJ6CLHlwIErnKxegVKiUGrX IC0PI3XHyJdC427BdYBgEq502CJB4/8K4O/h8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=As/ym8oz37ZFZtnV+BwS7q7FQaP2tW5+o8Ki67nRU4Nm1W4WzNAan6LKAfZya7nK2E 8hcklV5BMZJKHpRjdrtEtNLK8Z9JeGoe0PpY93UyVtoUYx3RnbYvppFky9ptI9S1yAnn QtqiBIz7OJ9ltcBxAvz//ihztIMi1s/AYhzUM= MIME-Version: 1.0 Received: by 10.140.201.8 with SMTP id y8mr5846401rvf.160.1243835714761; Sun, 31 May 2009 22:55:14 -0700 (PDT) Date: Mon, 1 Jun 2009 13:55:14 +0800 Message-ID: <30d841e90905312255sb4cc41rc9ea40664d85c2ce@mail.gmail.com> Subject: How to do with response.sendError() after the ServletOutputStream is established? From: =?GB2312?B?wffLrtL0?= To: users@tomcat.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org HI,ALL: Servlet code(deployed on Tomcat server): private void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { int count = 0; while(count< 1000000){ out.write(97); // writes 'a' to client count++; if(count == maxcount()){ throw new Exception("errors."); } } }catch(Exception e){ resp.sendError(605); return; } } private int maxcount(){ return 99999;// or return 15; } Client code: URL url = new URL(urlAddress); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.connect(); InputStream input = null; try { input = conn.getInputStream(); int count=0; while((input.read()) != -1){ count++; } System.out.println("total read is: " + count); } catch (IOException e) { int code = conn.getResponseCode(); System.out.println("Response code is: " + code); }finally{ Closer.close(input); } when the maxcount() returns 15, the exception is thrown out before the first buffer is flushed, then client can get the response code of: 605 but when the maxcount() returns 99999, the exception is thrown out after some buffers flushes, so the client can not get the exception anymore, the response code is 200. so, if I want to get the exception during the data transferring in the client, do you guys have any idea hot to do that? Thanks and Best Regards. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org