简体   繁体   中英

How to fetch localhost:8080 from full URL

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM