我正在尝试检查我的网址是否为 http/https,然后进行 AJAX 调用以根据第一个下拉列表中选择的值填充多个下拉列表。
var baseurl="<%=request.isSecure()%>";
if (baseurl=='true') {
var url =
"https://<%=request.getServerName()%><%=request.getContextPath()%>/JsonLookup?z=" + zone;
}
// if the protocol is 'http'
else
{
alert("inside protocol else");
var url = "http://<%=request.getServerName()%><%=request.getContextPath()%>/JsonLookup?z=" + zone;
alert("inside http:"+url);
}
当协议(protocol)为 http 时,我遇到问题,下拉列表不会更改。原因是,基本 url (isSecure()) 始终返回 true,即使它是 http。
任何人都可以帮我解决这个问题,我到底应该做什么才能使 request.isSecure() 对于 http 返回 false ?
最佳答案
不能使用没有主机名的引用吗?
/path/to/resource
而不是
http://myserver.com/path/to/resource
编辑:
您的示例如下所示:
var url = "/<%=request.getContextPath()%>/JsonLookup?z=" + zone;
alert("My root relative URL: "+url); }
关于java - 当连接为 http 时 request.isSecure() 返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429782/