سؤال

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