【问题标题】:Redirection from root (index.html) on JSF RichFaces从 JSF RichFaces 上的根目录 (index.html) 重定向
【发布时间】:2012-07-05 22:05:39
【问题描述】:

当我访问http://localhost:8080/CSPPortal/index.html 时尝试重定向到admin.xhtml 页面。根 index.html 包含

<html><head><meta http-equiv="Refresh" content="0; URL=pages/admin.jsf"/></head></html>

问题url 一直返回login.jsf 之前在 index.html 中声明。

尝试过:将一个空的index.jsf 页面添加到根文件夹。尝试将FacesServelet 映射到*.xhtml old answer on SO。尝试从 web.xml 中删除 &lt;welcome-file-list&gt;所有试验都失败了!!!! 任何关于哪里出了问题的建议都将非常感激。

这里是web.xml内容:

<servlet>
 <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
 <welcome-file>index.html</welcome-file>
 </welcome-file-list>
</web-app>

faces-config.xml中的导航规则如下,因为我还没有admin.xhtml的链接:

<navigation-rule>
 <from-view-id>/pages/login.xhtml</from-view-id>
 <navigation-case>
  <from-outcome>result</from-outcome>
  <to-view-id>/pages/result.xhtml</to-view-id>
 </navigation-case>
</navigation-rule>

使用 JBoss AS 7.1、RichFaces 4.0、JSF 2.0(通过 JBoss 工具)

【问题讨论】:

    标签: jsf redirect navigation richfaces


    【解决方案1】:

    由于URL是由浏览器调用的,所以需要这样解析url:

    <meta http-equiv="Refresh" content="0; URL=#{request.contextPath}/pages/admin.jsf"/>
    

    另见:

    【讨论】:

    • 当问题出在路径时,您的建议有效。但这是不同的。 RichFaces x.x 需要有一个 index.jsf 文件来处理,可以直接创建并留空。这解决了问题。
    【解决方案2】:

    从 JSF RichFaces 上的根目录 (index.html) 重定向

    1.放入xhtml文件。

    <html>
      <head>
        <meta http-equiv="Refresh" content="0; URL=index.jsf">
      </head>
    </html>
    

    2.Web.xml文件

    <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    

    【讨论】:

      【解决方案3】:

      externalContext 方法对我来说效果很好。

      <h:body>
        #{facesContext.externalContext.response.sendRedirect('pages/admin.jsf')}
      </h:body>
      

      【讨论】:

        猜你喜欢
        • 2017-02-20
        • 2016-09-19
        • 2015-10-21
        • 1970-01-01
        • 2014-10-09
        • 2015-09-02
        • 1970-01-01
        • 2019-07-20
        • 2021-11-26
        相关资源
        最近更新 更多