【问题标题】:JSF + Openshift redirect not workingJSF + Openshift 重定向不起作用
【发布时间】:2015-10-12 20:16:49
【问题描述】:

我正在使用 JSF 2 OpenShift(显然是 JBoss 7 服务器)做一个项目,但我无法通过 Bean 重定向来解决问题。我正在用 Glassfish 在本地尝试一切。当我尝试访问“access.xhml”页面时出现我的问题,为了监控登录的用户,我输入了以下内容:

<f:metadata>
    <f:event type="preRenderView" listener="#{sesion.checkSession()}" />
</f:metadata>

在方法的定义中我有以下内容

public void checkSession() throws IOException{
    faceContext=FacesContext.getCurrentInstance();
    httpServletRequest=(HttpServletRequest)faceContext.getExternalContext().getRequest();
    if(httpServletRequest.getSession().getAttribute("connected")==null)
    {
        faceContext.getExternalContext().redirect(faceContext.getExternalContext().getRequestContextPath() + "/index.xhtml"); // For local changes
    }
}

证明什么返回

faceContext.getExternalContext().getRequestContextPath()

我注意到它始终是 " " ,这向我表明重定向应该转到根目录。关键是当我尝试直接输入 www.my-app.rhcloud.com/access.xhtml 时总是抛出 500 错误

Exception when handling error trying to reset the response.: java.lang.IllegalStateException
at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl...
at org.sindicatopygp.beans.SessionBean.checkSession(SessionBean.java:43)

有什么想法吗?我们感谢

【问题讨论】:

  • 确切的完整消息标题是什么?只有Exception when handling error trying to reset the response.: java.lang.IllegalStateException吗?
  • 完整的异常太大了,这个异常一定是问题所在(我猜)。其他的是级联异常。

标签: java jsf jsf-2


【解决方案1】:

我解决了。由于某种原因 index.xhtml 无法识别该文件,如果重定向到 servlet root 并成功重定向到文件 index.xhtml。解决办法

public void checkSession() throws IOException{
    if(httpServletRequest.getSession().getAttribute("connected")==null)
    {
        try {
            faceContext.getExternalContext().redirect("/index.xhtml"); //For logged users
        } catch (Exception e) {
            try {
                faceContext.getExternalContext().redirect("/"); //For external visitors
            } catch (Exception ex) {
                //For other problems...
            }
        }
    }
}

【讨论】:

  • @Gonzalo Mendoza 担任总裁
猜你喜欢
  • 2011-02-09
  • 2023-03-23
  • 1970-01-01
  • 2012-03-22
  • 2010-12-13
  • 1970-01-01
  • 2021-02-19
  • 2017-10-08
  • 1970-01-01
相关资源
最近更新 更多