0

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?

4

1 回答 1

0

像这样的东西将获取服务器名称并将其添加到 httpsession

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

然后,您可以将其添加到会话中,并在带有表达式语言的 jsp 中使用它,如下所示:

${serverName}
于 2013-05-23T10:22:28.670 回答