JSP or JavaScript equivalent to PHP's $_SERVER[“HTTP_HOST”]?

[亡魂溺海] 提交于 2019-11-30 14:37:47

What you need is:

request.getServerName()

An example:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

The location object has several properties, and the one you'd want is hostname.

Or, you can optionally just use a root-relative URL and just set the pathname property and not mess with the host business at all!

location.pathname = "/store/results/index.jsp";

Javascript:

var server = window.location.hostname;

You really should have search for this but in JSP it's :

request.getRemoteHost()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!