Glassfish 3.1.1 中从 http 传输到 https

发布于 2024-12-15 21:47:05 字数 971 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫以 2024-12-22 21:47:05

您无法通过导航案例更改 HTTP 方案。导航箱基本上起到前进的作用。您需要发送 HTTP 重定向。您可以使用 ExternalContext#redirect() 为此。

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect("https://" + request.getLocalAddr() + ":8181" + request.getContextPath() + "/bookSeat.xhtml");

您只需将 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.

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect("https://" + request.getLocalAddr() + ":8181" + request.getContextPath() + "/bookSeat.xhtml");

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 by ExternalContext#getRemoteUser().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文