【问题标题】:Transferring from http to https in Glassfish 3.1.1在 Glassfish 3.1.1 中从 http 传输到 https
【发布时间】:2011-11-15 19:47:47
【问题描述】:

我正在使用 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 文件中添加导航规则。

如果是这样,我将如何编写导航规则?

【问题讨论】:

    标签: jsf jsf-2 glassfish-3


    【解决方案1】:

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

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

    您只需要在 bean 操作方法中添加一个throws IOException


    与具体问题无关,您为什么不通过 HTTPS 登录?您的问题表明您正在通过 HTTP 登录,从而通过网络发送未加密的用户名/密码。此外,应尽可能避免从 JSF 的封面下获取原始 Servlet API。您可以通过ExternalContext#getRequestParameterMap() 或者更好的是通过@ManagedProperty<f:viewParam> 获取HTTP 请求参数。可以通过ExternalContext#getRemoteUser()获取远程用户。

    【讨论】:

    • 感谢您的回答,--无关,谢谢,我稍后会介绍。
    • @BalusC - 我正在尝试使用这种方法从 https 转到 http。因此,使用容器安全登录后,我希望欢迎页面切换回 http。我调用重定向(从欢迎页面)并最终回到登录页面。有任何想法吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-10-01
    • 2012-02-26
    • 1970-01-01
    • 2011-02-10
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多