Jsf 添加omnifaces项目在重定向时提供了错误的url
在jsf项目中使用omnifaces 1.6,在glassfish 3.1.2上使用primefaces 3.5Jsf 添加omnifaces项目在重定向时提供了错误的url,jsf,primefaces,glassfish,omnifaces,Jsf,Primefaces,Glassfish,Omnifaces,在jsf项目中使用omnifaces 1.6,在glassfish 3.1.2上使用primefaces 3.5 FacesContext.getCurrentInstance().getExternalContext().redirect("localhost/my-project/views/index.jsf"); 使用此代码将重定向到url为localhost/my project/ 这个问题是当添加了omnifaces而没有omnifaces时,函数可以正常工作,没有问题我不知道
FacesContext.getCurrentInstance().getExternalContext().redirect("localhost/my-project/views/index.jsf");
使用此代码将重定向到url为localhost/my project/
这个问题是当添加了omnifaces而没有omnifaces时,函数可以正常工作,没有问题我不知道您期望的是什么,但是当您重定向到
localhost/my project/
时,重定向到带有urllocalhost/my project/
的页面似乎是正确的行为
可能您错过了该端口(例如重定向到localhost:8080/my project/
),但通常情况下,它不打算重定向到包含localhost的URL,而是重定向到特定页面(例如重定向到index.jsf
或index.xhtml
)。您甚至不需要webapp上下文(即myproject
),只需重定向到“主页”,如下所示:
FacesContext.getCurrentInstance().getExternalContext().redirect("home.xhtml");
这不是默认行为。您是否在
web.xml
或faces config.xml
中更改了任何内容?也许与FacesView有关?在我的web.xml中,我使用的是auth方法表单,当打开index.jsf时,会打开一个指向登录页面的重定向,在index.jsf页面的preRenderView中,我调用这行代码FacesContext.getCurrentInstance().getExternalContext().redirect(“localhost/my project/views/index.jsf”)代码>它将我重定向到localhost/my project/而不是index.jsf,在这里重定向url是正确的,一个战争风格的SSCCE会很有帮助。我至少可以说,给定的重定向URL首先确实很奇怪,正如unwichtich的答案所示。可能很奇怪,但是如果没有omniface jar文件,重定向是正确的,同时添加jar文件,重定向更改如所示,我无法回答这个问题,直到我看到SSCCE带有战争的味道。