[英]JSF + Openshift redirect not working
我正在使用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)
有任何想法吗? 我们感谢
我解决了。 由于某种原因,如果将index.xhtml重定向到servlet根目录并成功重定向到文件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...
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.