这是我的项目的结构(正是这五个文件):
/p1
pom.xml
/src
/main
/java
/webapp
a.html
b.xhtml
/WEB-INF
faces-config.xml
web.xml
我正在将此 WAR 部署到 GlassFish,并且可以成功访问此 URL:http://localhost:8080/p1/a.html
。当我尝试打开 http://localhost:8080/p1/b.xhtml
时,我收到一条消息
The requested resource (/p1/b.xhtml) is not available.
我做错了什么?
ps。我的依赖项来自 pom.xml
:
...
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>${facelets.version}</version>
</dependency>
...
这是我的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>*.xhtml</url-pattern>
</servlet-mapping>
我的faces-config.xml
:
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
最佳答案
对于 Maven 端,一切看起来都不错,只是还应该提供
。实际上,我使用以下依赖项:
<!-- This dependency will bring in everything we need for JAVA EE6 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
对于 JSF 部分,服务器日志中没有任何内容?以防万一,您可以将以下内容添加到您的 web.xml
中,看看是否获得更有用的输出:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
顺便说一句,您不需要 faces-config.xml
,因为 Facelets 是 JSF 2.0 中的默认 View 处理程序。但这应该不是问题。
PS:就个人而言,我更喜欢将 Faces Servlet
映射到 *.jsf
之类的东西上(以清楚地消除任何映射的 url 与实际 之间的关联。 xhtml
Facelet 页面将由 Faces Servlet 处理)。
另请参阅
关于java - 我应该在哪里放置 XHTML 文件才能使其在 GlassFish Web 容器中可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3387406/