From users-return-209243-apmail-tomcat-users-archive=tomcat.apache.org@tomcat.apache.org Wed Mar 03 14:29:52 2010 Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 35299 invoked from network); 3 Mar 2010 14:29:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 3 Mar 2010 14:29:51 -0000 Received: (qmail 92249 invoked by uid 500); 3 Mar 2010 14:29:40 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 92195 invoked by uid 500); 3 Mar 2010 14:29:40 -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 92186 invoked by uid 99); 3 Mar 2010 14:29:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Mar 2010 14:29:40 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of aw@ice-sa.com designates 212.85.38.228 as permitted sender) Received: from [212.85.38.228] (HELO tor.combios.es) (212.85.38.228) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Mar 2010 14:29:32 +0000 Received: from localhost (localhost [127.0.0.1]) by tor.combios.es (Postfix) with ESMTP id 2E14F226129 for ; Wed, 3 Mar 2010 15:29:11 +0100 (CET) Received: from tor.combios.es ([127.0.0.1]) by localhost (tor.combios.es [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id utICLAR3+eKR for ; Wed, 3 Mar 2010 15:29:11 +0100 (CET) Received: from [192.168.245.129] (p549EA955.dip0.t-ipconnect.de [84.158.169.85]) by tor.combios.es (Postfix) with ESMTPA id C16E8226109 for ; Wed, 3 Mar 2010 15:29:10 +0100 (CET) Message-ID: <4B8E7234.1020206@ice-sa.com> Date: Wed, 03 Mar 2010 15:29:08 +0100 From: =?ISO-8859-1?Q?Andr=E9_Warnier?= Reply-To: Tomcat Users List User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: getServerName returns 'localhost' References: <27767838.post@talk.nabble.com> <4B8E5DFB.2030707@ice-sa.com> <27768081.post@talk.nabble.com> <4B8E676F.9030102@ice-sa.com> <4B8E6872.7080402@ice-sa.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Peter Crowther wrote: > On 3 March 2010 13:47, André Warnier wrote: >> André Warnier wrote: >>> vgud wrote: >>>> My server responds to different domain names, and I want to know which >>>> one users use. > [...] >> More precisely : >> >> getRemoteAddr >> >> public java.lang.String getRemoteAddr() >> >> Returns the Internet Protocol (IP) address of the client or last proxy >> that sent the request. For HTTP servlets, same as the value of the CGI >> variable REMOTE_ADDR. > > Andre, you're answering the question of "which client sent this request?" > > The OP is asking a different question: "What hostname did the client > send this request to?" > > I'd parse the host header in the request to find out, but that's just me! > You are right, I am off-base here, apologies. String hostname = request.getHeader("Host") should work. But then, the question is, according to the OP, request.getServerName() returns "localhost", although that is very unlikely to have been used by the client in the Host header. However, the java API says : ServletRequest.getServerName public java.lang.String getServerName() Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address. Returns: a String containing the name of the server That does not seem to work in his case. Does it only work when the or tags with the corresponding names are set ? (A question for people who like to scan the code.. Christopher ?) --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org