There are no good ways to do this.
Generally speaking, the server does not know the name that can be used to access it from the outside. In fact, it is HttpServletRequest.getServerName()also not a solution, because it returns the name used to send this particular request, and not the canonical name in which you want your server to be known.
..