get host from request object java

Java
request.getRequestURL().toString().replace(request.getRequestURI(), "")
Source

Also in Java: