2
Я создаю новый URL-адрес в Spring MVC-контроллере, который будет передан клиенту. В настоящее время я пытаюсь это:Получить имя используемого протокола от HttpServletRequest?
// httpRequest is the current HttpServletRequest
new URL(httpRequest.getProtocol(),
httpRequest.getServerName(),
httpRequest.getServerPort(),
httpRequest.getContextPath().concat("/foo/bar.html"));
Проблема заключается в том, что httpRequest.getProtocol()
дает мне "HTTP/1.1" вместо просто "HTTP". Я могу обрезать его, но задавался вопросом, был ли более элегантный способ.
Возможный дубликат http://stackoverflow.com/questions/19598690/how-to-get-host-name-with-port-from-a-http -или-https-request & http://stackoverflow.com/questions/1104611/java-string-representation-of-just-the-host-scheme-possible-port-from-servlet – OO7