title: Absolute URL in java
body: <p>I am trying to get absolute URL in java class, but getting an error even after type casting it to Object.</p>
  
  <p>Any suggestions </p>
  
  <pre><code>   String file = ((Object) request).getRequestURI();
       if (((Object) request).getQueryString() != null) {
          file += '?' + ((Object) request).getQueryString();
       }
       URL reconstructedURL = new URL(request.getScheme(),
                                      request.getServerName(),
                                      request.getServerPort(),
                                      file);
       System.out.println(URL.toString());
  </code></pre>