title: Get full URL and query string in Servlet for both HTTP and HTTPS requests
body: <p>I am writing a code which task is to retrieve a requested URL or full path. I've written this code: </p>
  
  <pre><code>HttpServletRequest request;//obtained from other functions
  String uri = request.getRequestURI();
  if (request.getQueryString() != null)
      uri += "?" + request.getQueryString();
  </code></pre>
  
  <p>So, when I browse <code>http://google.com?q=abc</code> it is OK (correct).
  But there is problem when I browse <code>https://google.com</code>. The value of <code>uri</code> is <code>http://google.com:443google.com:443</code>, So the program doesn't only when <code>HTTPS</code> is used.</p>
  
  <p>And the output is same for <code>request.getRequestURL().toString()</code>. </p>
  
  <p>What is the solution?   </p>