Get hostname and server port


I have a web application that sends emails with a link to access a module of my application, but I have been doing it in a fixed way with the IP address and port already established. Now my application is going to upload to production, and the post office tells me that my application will be assembled in a cluster, so I must obtain these two parameters dynamically, no matter where it is executed How do I do it?

asked by J. Cristian 17.03.2017 в 21:53

1 answer


Hi, you can use ServletRequest:.

ServletRequest.getLocalName() returns hostname.
ServletRequest.getLocalAddr() returns IP.
ServletRequest.getLocalPort() returns puerto.

ServletRequest Interface

answered by 17.03.2017 в 23:07