You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paritosh Patel <to...@ocpinc.net> on 2010/09/17 16:15:58 UTC
How to get Tomcat IP address during app startup?
My web application needs to know the server IP/Port address during
its initialization. How can I determine that? (I was trying to stay
server agnostic as much as possible... if that is not possible, then I
will write specific code for Tomcat.
I have searched everywhere for this answer on the web and in this forum.
I understand it can be found from the HttpServletRequest class, but that is
too late.
I have a servlet context listener, but I cannot get the IP address from
there either.
I would appreciate any help or ideas on this. Thanks.
- Tosh
RE: How to get Tomcat IP address during app startup?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Pid [mailto:pid@pidster.com]
> Subject: Re: How to get Tomcat IP address during app startup?
> Tomcat listens on whichever IP address is configured
> in your connector. If you don't specify an IP address,
> then it listens on 0.0.0.0.
> The point I'm making is that Tomcat might not know the
> address you want/need.
If the OP is willing to restrict Tomcat to using a single IP address, he could set that in a Java system property, and then use an attribute like address=${configured.ip.address} in each <Connector>. The webapp initialization code could then retrieve the value from the system property, as Tomcat does. Not terribly elegant, but it might suffice...
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get Tomcat IP address during app startup?
Posted by Pid <pi...@pidster.com>.
On 17/09/2010 15:15, Paritosh Patel wrote:
> My web application needs to know the server IP/Port address during
> its initialization. How can I determine that? (I was trying to stay
> server agnostic as much as possible... if that is not possible, then I
> will write specific code for Tomcat.
>
> I have searched everywhere for this answer on the web and in this forum.
Everywhere on the web? Even Google can't manage that.
> I understand it can be found from the HttpServletRequest class, but that is
> too late.
>
> I have a servlet context listener, but I cannot get the IP address from
> there either.
>
> I would appreciate any help or ideas on this. Thanks.
Tomcat listens on whichever IP address is configured in your connector.
If you don't specify an IP address, then it listens on 0.0.0.0.
HttpServletRequest will only tell you what the client requested, which
may or may not be the correct answer, depending on whether your app is
behind a proxy or not.
The point I'm making is that Tomcat might not know the address you
want/need.
java.net.InetAddress may help, depending on what it is you're actually
trying to achieve. There was a discussion about this last year, if I
remember correctly, you may wish to search the archives again.
p