【问题标题】:redirect to html page using jsf使用jsf重定向到html页面
【发布时间】:2014-07-03 17:59:57
【问题描述】:

我不明白为什么这段代码不能正确地将我重定向到我想要的 html 页面。这是我正在使用的代码:

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

它似乎正在重定向页面,但没有出现任何内容,即使我在 html 文件中有内容。 xhtml文件的字符串应该怎么放?

感谢您的帮助

【问题讨论】:

  • 尝试使用“Start.jsf”。更多信息:1) 如果代码是常规操作方法的一部分,您可以在 faces-config.xml 中使用来自navigation-case 的重定向结果。 2)在URL中添加getContextPath(),例如:ec.redirect(getRequest().getContextPath() + "/login.jsf?" + Constants.PARAM1 + "=" + bean.getValue());

标签: jsf redirect primefaces xhtml


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

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

      希望,这对某人有所帮助。

      【讨论】:

      • 这完全取决于您的配置。拥有 .faces 扩展名甚至比 JSF 中的规则更例外。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      • 2013-11-26
      相关资源
      最近更新 更多