code: public static String getUrl(final HttpServletRequest request) {
      try {
        final StringBuffer sb = request.getRequestURL();
        if (sb != null) {
          return sb.toString();
        }
  
        // Presumably portlet - see what happens with uri
        return request.getRequestURI();
      } catch (Throwable t) {
        return "BogusURL.this.is.probably.a.portal";
      }
    }
docs: Returns the String url from the request.
  
  @param   request     incoming request
  @return  String      url from the request