Uzyskaj pełny adres URL i ciąg zapytania w Servlet dla żądań HTTP i HTTPS

Piszę kod, którego zadaniem jest pobranie żądanego adresu URL lub pełnej ścieżki. Napisałem ten kod:

HttpServletRequest request;//obtained from other functions
String uri = request.getRequestURI();
if (request.getQueryString() != null)
    uri += "?" + request.getQueryString();

Więc kiedy przeglądamhttp://google.com?q=abc jest OK (poprawne). Ale jest problem podczas przeglądaniahttps://google.com. Wartośćuri jesthttp://google.com:443google.com:443, Więc program nie działa tylko wtedy, gdyHTTPS jest używany.

A wyjście jest takie samo dlarequest.getRequestURL().toString().

Jakie jest rozwiązanie?

questionAnswers(3)

yourAnswerToTheQuestion