使用jsf重定向到html页面
我不明白为什么这段代码不能将我正确地重定向到我想要的html页面。这是我正在使用的代码:使用jsf重定向到html页面,jsf,redirect,primefaces,xhtml,Jsf,Redirect,Primefaces,Xhtml,我不明白为什么这段代码不能将我正确地重定向到我想要的html页面。这是我正在使用的代码: String url = "Start.xhtml"; FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); try { ec.redirect(url);
String url = "Start.xhtml";
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
try {
ec.redirect(url);
}catch (IOException ex) {
ex.printStackTrace();
}
它似乎正在重定向页面,但没有显示任何内容,即使我在html文件中有一些内容。如何放置xhtml文件的字符串
感谢您的帮助您可以尝试以下解决方案:
String url = "Start";
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
try {
ec.redirect(url);
}catch (IOException ex) {
ex.printStackTrace();
}
<>你必须考虑应用程序的上下文根。在大多数情况下是这样的:
String url = "/ApplicationName/faces/Start.jsf";
try {
FacesContext.getCurrentInstance().getExternalContext.redirect(url);
} catch (IOException e) {
// error handling
}
当从bean重定向到另一个XHTML屏幕时,使用'.faces'扩展名而不是'.XHTML',如下所示
FacesContext.getCurrentInstance().getExternalContext().redirect("Start.faces?re-direct=true");
希望,这对某些人有所帮助。尝试使用“Start.jsf”。更多信息:1)如果代码是常规操作方法的一部分,则可以使用faces-config.xml中导航案例的重定向结果。2) 在URL中添加
getContextPath()
,例如:ec.redirect(getRequest().getContextPath()+“/login.jsf?”+Constants.PARAM1+”=“+bean.getValue())代码>这完全取决于您的配置。在JSF中,使用.faces扩展名更像是一个例外,而不是一个规则。