title: Getting request URL in a servlet
body: <p>I want to know the difference between the below two methods of getting a request URL in servlet.</p>
  
  <p>Method 1:</p>
  
  <pre><code>String url = request.getRequestURL().toString();
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>url = request.getScheme()
        + "://"
        + request.getServerName()
        + ":"
        + request.getServerPort()
        + request.getRequestURI();
  </code></pre>
  
  <p>Are there any chances that the above two methods will give two different URLs?</p>