code: public static String getURLshp(final HttpServletRequest request) {
      String scheme = request.getScheme();
      StringBuilder sb = new StringBuilder(scheme);
  
      sb.append("://");
      sb.append(request.getServerName());
  
      int port = request.getServerPort();
  
      if ("http".equalsIgnoreCase(scheme) && (port == 80)) {
        return sb.toString();
      }
  
      if ("https".equalsIgnoreCase(scheme) && (port == 443)) {
        return sb.toString();
      }
  
      sb.append(":");
      sb.append(port);
  
      return sb.toString();
    }
docs: Returns the scheme + host + port part of the url.
  This allows us to link to services on the same machine.
  <p>For example, a URL of http://myhost.com:8080/myapp/doit.do will get a
  result "http://myhost.com:8080"
  
  @param request
  @return scheme + host + port