VDP
VDP

Reputation: 6420

How do I get the real server name in jsp, not the proxy's name

I have following (simplified) setup.

Setup

From the client I call http://somedomain.com/my.jsp via the proxy it's forwarded to apache 1 or apache 2

In my jsp I want the server1-domain.com or server2-domain.com and not somedomain.com

request.getServerName() gives me somedomain.com in the header the 'Host' param is also somedomain.com

It seems similar but just the opposite to: tomcat-getheaderhost-vs-getservername

But I cannot turn of 'ProxyPreserveHost' as I am not the only one on the cluster... Optimal solution is not having to change anything to the domaincontroller/loadbalancer/apaches

Can I get it via just a JSP method/param?

Upvotes: 2

Views: 6937

Answers (1)

VDP
VDP

Reputation: 6420

I ended up using this:

String hostname = InetAddress.getLocalHost().getHostName();

Upvotes: 2

Related Questions