質問

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