使用jsf重定向到html页面

问题描述 投票:0回答:3

我无法弄清楚为什么这段代码没有正确地重定向到我想要的html页面。这是我正在使用的代码:

String url = "Start.xhtml";
           FacesContext fc = FacesContext.getCurrentInstance();
           ExternalContext ec = fc.getExternalContext();
           try {
                ec.redirect(url);
           }catch (IOException ex) {
                ex.printStackTrace();
           }   

它似乎是重定向页面,但没有出现,即使我有html文件中的东西。我应该如何把xhtml文件的字符串?

谢谢您的帮助

jsf redirect primefaces xhtml
3个回答
1
投票

您必须考虑应用程序的上下文根。在大多数情况下,它是这样的:

String url = "/ApplicationName/faces/Start.jsf";

try {
   FacesContext.getCurrentInstance().getExternalContext.redirect(url);
} catch (IOException e) {
   // error handling
}

-1
投票

你可以尝试这个解决方案:

 String url = "Start";
           FacesContext fc = FacesContext.getCurrentInstance();
           ExternalContext ec = fc.getExternalContext();
           try {
                ec.redirect(url);
           }catch (IOException ex) {
                ex.printStackTrace();
           }  

-2
投票

从bean重定向到另一个XHTML屏幕时,使用'.faces'扩展名而不是'.xhtml',如下所示

FacesContext.getCurrentInstance().getExternalContext().redirect("Start.faces?re-direct=true");

希望,这有助于一些人。

© www.soinside.com 2019 - 2024. All rights reserved.