【问题标题】:index.html change to index.xhtmlindex.html 更改为 index.xhtml
【发布时间】:2015-07-15 08:34:44
【问题描述】:

在尝试注销我的应用程序时,我收到以下错误消息:

com.sun.faces.context.FacesFileNotFoundException: /index.xhtml Not Found in ExternalContext as a Resource

要注销,我将在PhaseListener.beforePhase(PhaseEvent phaseEvent) 中执行以下步骤:

// Redirect to index.html
NavigationHandler nh = fctx.getApplication().getNavigationHandler();
String action_outcome = "/index.html";
nh.handleNavigation(fctx, null, action_outcome);

我的 web.xml 如下:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
        id="WebApp_ID" 
        version="3.0">

        <context-param>
              <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
              <param-value>.xhtml</param-value>
          </context-param>

          <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
          </servlet>

      <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
        <filter-name>trinidad</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
      </filter-mapping>

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

          <welcome-file-list>
            <welcome-file>index.html</welcome-file>
          </welcome-file-list>
          <security-constraint>
            <display-name>Restrict raw XHTML Documents</display-name>
            <web-resource-collection>
              <web-resource-name>XHTML</web-resource-name>
              <url-pattern>*.xhtml</url-pattern>
            </web-resource-collection>
            <auth-constraint/>
          </security-constraint>
          <login-config>
            <auth-method>BASIC</auth-method>
          </login-config>
</web-app>

我的应用中没有 index.xhtml,但我有并且想要保留它的 index.html 文件。

为什么将我的结果操作赋予 NavigationHandler 重命名为 index.xhtml ?

我该如何避免呢?

【问题讨论】:

    标签: jsf-2 url-rewriting


    【解决方案1】:

    NavigationHandler 需要一个 JSF 页面,而不是非 JSF 页面。此外,您实际上根本没有发送真正的重定向,这与代码注释所说的相反。你只是在这里执行前锋。

    执行真正的重定向将解决您的问题。具体做法如下:

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.redirect(ec.getRequestContextPath() + "/index.html");
    

    另见:


    与具体问题无关,在阶段侦听器中执行授权工作很臭。您是否考虑过 servlet 过滤器?

    另见:

    【讨论】:

    • 您的解决方案正在运行,感谢您的建议和链接。我会花时间阅读它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2015-03-09
    • 2020-12-08
    • 2013-11-22
    • 2021-06-06
    相关资源
    最近更新 更多