com.sun.faces.context.FacesFileNotFoundException:/protected-area/index.xhtml在ExternalContext中找不到资源

时间:2013-09-19 21:58:49

标签: jsf jsf-2 navigation filenotfoundexception

我正在使用jee7开发一个Web应用程序,我会将我的.xhtml文件组织到不同的文件夹中。我尝试设置web.xml和faces-config.xml文件但是当我点击一个按钮输入文件夹时我遇到了这个问题,

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

当我想要同时输入文件夹“protected-area”和“public”时出现问题。 我希望我很清楚,我不明白,因为它不起作用。 非常感谢您的帮助。

这些是我的文件。

的index.xhtml

<h:head>
    <title>jingsen</title>
</h:head>
<h:body>
    Select where you want to go:

    <h:form>
        <h:commandButton value="protected area" action="protected-area"></h:commandButton>
        <h:commandButton value="public" action="public"></h:commandButton>
        <h:commandButton value="testtest" action="test"></h:commandButton>
    </h:form>
</h:body>

的web.xml

    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</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>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jingsen-realm</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/error.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-constraint>
    <display-name>Admin Pages</display-name>
    <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <description/>
        <url-pattern>/protected-area/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>admin</role-name>
        <role-name>cassa</role-name>
        <role-name>cameriere</role-name>
        <role-name>cucina</role-name>
        <role-name>bar</role-name>
    </auth-constraint>
</security-constraint>
<security-role>
    <role-name>admin</role-name>
</security-role>
<security-role>
    <role-name>cameriere</role-name>
</security-role>
<security-role>
    <role-name>cucina</role-name>
</security-role>
<security-role>
    <role-name>bar</role-name>
</security-role>

面-config.xml中

<navigation-rule>
    <from-view-id>index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>protected-area</from-outcome>
        <to-view-id>/protected-area/index.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
    <navigation-case>
        <from-outcome>public</from-outcome>
        <to-view-id>/public/index.xhtml</to-view-id>
        <redirect/>
    </navigation-case>

    <navigation-case>
        <from-outcome>test</from-outcome>
        <to-view-id>prova.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

1 个答案:

答案 0 :(得分:1)

确保index.xhtml位于webapp文件夹下。如果不是,请在欢迎标记中的index.xhtml之前添加子文件夹。例如:

<welcome-file-list>
<welcome-file>/pages/index.xhtml</welcome-file>
</welcome-file-list>