2015-04-06 50 views
3

在我们的项目之一,我们仍然要使用JSF 1.2 + Tomcat的6和问题是,当我送https - 请求到服务器,并试图获得请求的URL托管bean如下:为什么request.getRequestURL()返回非https网址?

ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); 
HttpServletRequest request = (HttpServletRequest)context.getRequest(); 
String url = request.getRequestURL().toString() 

发送请求按钮只是一个提交按钮看上去如下:

<h:form id="contactform"> 
    <h:commandButton id="submit" action="#{forgotPasswordBean.doSend}" 
</h:form> 

我得到httpshttp基于URL这一翻译。 在Web浏览器的调试面板我确信,一个https -request实际发送,但URL中包含的链接,只是http请求。什么是问题或者它只是一个错误?

回答

2

HttpServletRequest#getRequestUrl()包含协议,服务器名称,端口号和服务器路径,即它应该包含https如果连接实际上是安全的并且处于HTTP状态。

然而,这并不确定是否连接可靠的唯一途径。该ServelRequest接口定义了两个更多的选择(ServletRequest#getScheme()ServletRequest#isSecure())如果请求被固定或不检测:

String scheme = request.getScheme(); //will return "https" when connection is secured 
//or 
boolean isSecured = request.isSecure(); //will return true when connection is secured 

更多信息:

+0

那么,request.isSecure();为我返回false ... – user3663882 2015-04-06 11:06:40

+0

request.getScheme();返回http ...我真的不知道这件事...... – user3663882 2015-04-06 11:07:29

+2

其实,问题是我们有一个负载blancer发送纯http请求。 – user3663882 2015-04-06 11:13:17

5

这种行为可以发生,如果您在应用程序前有一个负载均衡器。即使请求是在HTTPS中完成的,负载均衡器会将它们重新发布为导致此行为的普通http请求。

一个例子使用GAE(谷歌应用程序引擎)时。您可以使用HTTPS端点(https://my-app.appspot.com),但您的应用将继续接收HTTP中的所有请求。

这是由@ user3663882在批准的答案的评论下指出的。

+0

一个好的负载均衡器至少传递了一些额外的http头部,表明这是一个安全的连接 – Kukeltje 2017-10-03 19:31:54

相关问题