code: public static String getLocation (HttpServletRequest req)
      {
          StringBuffer rurl = req.getRequestURL();
          String qs = req.getQueryString();
          if (qs != null) {
              rurl.append("?").append(qs);
          }
          return rurl.toString();
      }
docs: Reconstructs the current location (URL) from the request and
  servlet configuration (which is the only way to know which server
  we're on because that's not provided in the request) and returns
  it.
  
  @return The URL that represents our current location.