0

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.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Tsu
  • 33
  • 4

1 Answers1

1

It can be achieved in one line of code

String hostName = request.getHeader("host");
System.out.println(" HostName : " + hostName);
Rmahajan
  • 1,311
  • 1
  • 14
  • 23