Вопрос

I am working on a web application in jsp in which I need to get the local domain name. For example if working on local server, I want to get local server name as "localhost" or while working on some online server, the server name as "www.server.com".

Is there any method to get the domain name of local server in jsp?

Это было полезно?

Решение

Something like this will get the server name and add it to the httpsession

String serverName = HttpServletRequest.getServerName();
session.setAttribute("serverName", serverName);

You can then add add this to the session, and use it in the jsp with expression language like so:

${serverName}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top