【发布时间】:2013-09-19 21:58:49
【问题描述】:
我正在使用 jee7 开发一个 Web 应用程序,我会将我的 .xhtml 文件组织到不同的文件夹中。我尝试设置 web.xml 和 faces-config.xml 文件,但是当我单击按钮进入文件夹时,我遇到了这个问题,
com.sun.faces.context.FacesFileNotFoundException: /protected-area/index.xhtml Not Found in ExternalContext as a Resource
当我想同时进入“保护区”和“公共”文件夹时出现问题。 我希望我很清楚,我不明白,因为它不起作用。 非常感谢您的帮助。
这些是我的文件。
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>
faces-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>
【问题讨论】:
-
“保护区”和“公共”是否与 WEB-INF 文件夹处于同一级别?
-
嗨!谢谢您的回复。我将文件夹放入 WEB-INF 而不是网页中,现在它可以工作了
-
在继续之前,请修正一个严重错误:如果唯一的目的是逐页导航而不是提交表单,请将
<h:commandButton>替换为<h:button>。顺便说一句,您的javax.faces.CONFIG_FILES配置条目很奇怪。摆脱它。
标签: jsf jsf-2 navigation filenotfoundexception