在我们的一个项目中,我们仍然必须使用JSF 1.2 + Tomcat 6,问题是当我向https
服务器发送-request并尝试在托管bean中获取请求的URL时,如下所示:
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest)context.getRequest();
String url = request.getRequestURL().toString()
Run Code Online (Sandbox Code Playgroud)
发送请求的按钮只是一个提交按钮,如下所示:
<h:form id="contactform">
<h:commandButton id="submit" action="#{forgotPasswordBean.doSend}"
</h:form>
Run Code Online (Sandbox Code Playgroud)
我得到了http
基于URL的intead https
.在Web浏览器的调试面板中,我确保https
实际发送了一个-request,但是URL包含一个只是http
请求的链接.什么问题或者只是一个错误?
Ale*_*lex 11
如果您在应用程序前面有一个负载均衡器,则会发生此行为.即使请求是在HTTPS中完成的,负载均衡器也会将它们重新发布为产生此行为的纯http请求.
一个例子是使用GAE(Google App Engine).您可以使用HTTPS端点(https://my-app.appspot.com),但您的应用将继续接收HTTP中的所有请求.
@ user3663882在批准的答案的评论中指出了这一点.
其中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
Run Code Online (Sandbox Code Playgroud)
更多信息:
归档时间: |
|
查看次数: |
6323 次 |
最近记录: |