I have a URL path as http://localhost:8080/welcome/this/is/a/test
My line in Java is
String domain = httpServletRequest.getServerName();
But with this I get "localhost". I want the port number as well I want to get only "localhost:8080" in my string.
It can be achieved in one line of code
String hostName = request.getHeader("host");
System.out.println(" HostName : " + hostName);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.