0

If we use it in the page http://www.somedomain.com/somepage..?=blah&two=blah, only www.somedomain.com have to be returned. I tried using

request.getScheme().toString() + "://" + request.getRemoteHost()`

But its returning an IP address, which is of no use for me. Kindly advice.

Thanks in advance

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
Immy
  • 57
  • 2
  • 10

1 Answers1

0

you should use getServerName() method which returns current domain name.

getServerName() 

Returns the host name of the server that received the request.

getRemoteHost() 

Returns the fully qualified name of the client that sent the request.

Source : http://docs.oracle.com/javaee/5/api/javax/servlet/ServletRequest.html

  • I tried getServerName() and it returns ip address of web server. – Immy May 23 '14 at 18:05
  • @MADTerry please add the reference from where you got this info, for example in this case I am assuming you copied this from here: http://docs.oracle.com/javaee/5/api/javax/servlet/ServletRequest.html – fmodos May 23 '14 at 18:06
  • 1
    @fmodos Sorry for that.Next time i would. – Madhurendra Sachan May 23 '14 at 18:07
  • @Immy Then have a look at this question http://stackoverflow.com/questions/10407203/tomcat-getheaderhost-vs-getservername .GetServerName is usually value taken from CGI variable `SERVER_NAME` – Madhurendra Sachan May 23 '14 at 18:09
  • @MADTerry Well I tried that also , but of no use as I ended up with Ip address again. – Immy May 23 '14 at 18:34
  • @Immy Have you verified `httpd passes the Host header provided by the client `. This is the issue your httpd is not passing original header sent by client – Madhurendra Sachan May 23 '14 at 18:38
  • @MADTerry can you specify where I need to place "ProxyPreserveHost On" in my web servers httpd.conf file, inside which section? As I have less idea about servers , any help will be great. – Immy May 23 '14 at 18:57
  • ` ProxyPreserveHost On ` an new directive.Read it here http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost – Madhurendra Sachan May 23 '14 at 19:02
  • @MADTerry Thanks for pointing out solution. Now my virtual host is like : ServerName www.somedomain.co.id ServerAlias www.somedomain.co.id DocumentRoot /var/www/html ErrorDocument 503 /_ui/welcometoSomeDomain.html ProxyPreserveHost On And then I tried accessing site as http://somedomain.co.id and is worked fine , this time I got domain name. But now I am unable to access the site as www.somedomain.co.id, its giving 500 page saying CMSsite not found. – Immy May 24 '14 at 02:31
  • @immy server configuration seems to be correct.You can check server error log to diagnose the problem. – Madhurendra Sachan May 24 '14 at 03:43