index.html change to index.xhtml



试图注销我的应用程序时,我有以下错误消息:

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文件。

为什么我的atemondy_action将navigationhandler重命名为index.xhtml?

我如何避免它?

NavigationHandler期望JSF页面,而不是非JSF页面。此外,您实际上根本没有发送真正的重定向,与代码评论所说的相反。您只是在这里表演。

执行真正的重定向将是解决问题的方法。如下:

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

另请参见:

  • 重定向和导航/向前以及何时使用什么?
  • 有什么区别?
  • 如何在JSF中导航?如何使URL反映当前页面(而不是先前的页面)

无关的到具体问题,在阶段侦听器臭时进行授权作业。您是否考虑过Servlet过滤器?

另请参见:

  • 使用phaselistener而不是servlet过滤器进行授权的限制
  • 未能从JSF phaselistener重定向
  • 如何在JSF 2.0中的会话无效?

相关内容

最新更新