Glassfish 3.1.1 中从 http 传输到 https
我正在使用 Glassfish 3.1.1 和 JSF 2.0:
我有以下代码:
public String doLoginOrCC() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.flightNumber = request.getParameter("flightNumber");
if (request.getRemoteUser() == null) {
return "login.xhtml";
} else {
return "https://" + request.getLocalAddr() + ":8181" + request.getContextPath() + "/bookSeat.xhtml";
}
}
如果用户未登录,则转到 login.xhtml。
如果用户已登录,则转到 https://localhost:8181/APP/bookSeat.xhtml
Unable to find matching navigation case with from-view-id '/flightInfo.xhtml' for action '#{bookSeatController.doLoginOrCC}' with outcome 'https://127.0.0.1:8181/PlaneTicketProgram5-war/bookSeat.xhtml'
我是否必须在 faces-config.xml 文件中添加导航规则?
如果是这样,我将如何编写导航规则?
I'm using Glassfish 3.1.1 and JSF 2.0:
I have the following code:
public String doLoginOrCC() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.flightNumber = request.getParameter("flightNumber");
if (request.getRemoteUser() == null) {
return "login.xhtml";
} else {
return "https://" + request.getLocalAddr() + ":8181" + request.getContextPath() + "/bookSeat.xhtml";
}
}
If user is not logged in then go to login.xhtml.
If user is logged in then go to https://localhost:8181/APP/bookSeat.xhtml
Unable to find matching navigation case with from-view-id '/flightInfo.xhtml' for action '#{bookSeatController.doLoginOrCC}' with outcome 'https://127.0.0.1:8181/PlaneTicketProgram5-war/bookSeat.xhtml'
Do I have to add a Navigation Rule in my faces-config.xml file.
If so how would I write the Navigation Rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过导航案例更改 HTTP 方案。导航箱基本上起到前进的作用。您需要发送 HTTP 重定向。您可以使用
ExternalContext#redirect()
为此。您只需将
throws IOException
添加到 bean 操作方法即可。与具体问题无关,您为什么不通过 HTTPS 登录?您的问题表明您正在通过 HTTP 登录,从而通过网络发送未加密的用户名/密码。另外,应尽可能避免从 JSF 底层获取原始 Servlet API。您可以通过 获取 HTTP 请求参数
ExternalContext#getRequestParameterMap()
或者更好的是@ManagedProperty
或 < a href="http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/viewParam.html" rel="nofollow">
。您可以通过 获取远程用户ExternalContext#getRemoteUser()
。You cannot change the HTTP scheme by a navigation case. A navigation case does basically a forward. You need to send a HTTP redirect instead. You can use
ExternalContext#redirect()
for this.You only need to add a
throws IOException
to the bean action method.Unrelated to the concrete problem, why aren't you logging in over HTTPS? Your problem suggests that you're logging in over HTTP which thus sends the username/password unencrypted over network. Also, grabbing the raw Servlet API from under the JSF covers should be avoided as much as possible. You can grab HTTP request parameters by
ExternalContext#getRequestParameterMap()
or, better, by@ManagedProperty
or<f:viewParam>
. You can get the remote user byExternalContext#getRemoteUser()
.