Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 96457 invoked from network); 12 Feb 2002 22:59:21 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 12 Feb 2002 22:59:21 -0000 Received: (qmail 27703 invoked by uid 97); 12 Feb 2002 22:59:04 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 27687 invoked by uid 97); 12 Feb 2002 22:59:04 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 27676 invoked from network); 12 Feb 2002 22:59:03 -0000 Message-ID: <025501c1b418$dbdd9030$408ace0a@vitria.com> Reply-To: "Yueming Xu" From: "Yueming Xu" To: Subject: Cannot get HTTP response code Date: Tue, 12 Feb 2002 15:58:58 -0700 Organization: Vitria MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0252_01C1B3DE.2E71B500" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_0252_01C1B3DE.2E71B500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi,=20 I have a servlet running in Tomcat, and it sometimes returns error by = calling HttpServletResponse.sendError(400, "Invalid request"). The following code works with Tomcat 4.0, it can display both regular = response (status 200) and error response (status 400.) However, in = Tomcat 3.2.1, I get an error:=20 java.net.ProtocolException: Can't reset method: already connected at = java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:106) at = sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnec= tion.java:405) So, I had to remove the call connection.connect() for the regular 200 = response to go through. However, the 400 error response will cause the = following exception: java.io.FileNotFoundException: http://localhost:8080/servlet/simple at = sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnect= ion.java:529) at = java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:145) What is the problem of this code? Is this a bug in Tomcat 3.x, or is it = an HTTP version issue? Thanks, Yueming [Code snipet ...] connection =3D (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setUseCaches(true); // this line is the solution and problem connection.connect(); // send request PrintWriter out =3D new PrintWriter( connection.getOutputStream() ); out.println(stringToSend); out.close(); // read response int status =3D connection.getResponseCode(); System.out.println("\nResponse Code: " + status); System.out.println("Response Message: " + = connection.getResponseMessage()); ------=_NextPart_000_0252_01C1B3DE.2E71B500--