[英]index.xhtml 404 error with Primefaces and Jboss
我正在使用JBoss AS 7.1 、 jsf 2.2和Java7构建一个新的 Maven 应用程序。 无论如何,我无法让它发挥作用。 Jboss 运行良好,我可以看到欢迎页面,但没有办法(我尝试了很多)看到我的index.xhtml
页面。 它一直给我一个404错误。
这是我的pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.metalacademy</groupId>
<artifactId>MetalAcademy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>MetalAcademy</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我在WEB-INF文件夹中的web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>MetalAcademy</display-name>
<!--
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
-->
<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>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
这是我的webapp文件夹中的index.xhtml
:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="">
</ui:composition>
<h:head>
<title>METAL ACADEMY</title>
</h:head>
<body>
<h1>Test Page</h1>
<h:commandButton value="Search" />
</body>
</html>
难道我做错了什么? 我想我尝试了一切……现在我被卡住了。
先感谢您!
404 通常意味着找不到页面。 这表明应用程序没有被部署,或者您引用了错误的名称。 您能否使用 JBoss 管理控制台检查应用程序是否正确部署?
我从 POM 中缺少的是maven-war-plugin
,否则你如何创建需要部署的 .war ?
在 web.xml 文件中,您将需要 index.xhtml 的<welcome-file-list>
(而不是其他文件)。 没有它,默认的初始页面是 index.html,但在 Wildfly 中,如果 index.html 不存在,这会给我一个“禁止”错误而不是 404。
在 index.xhtml 中,带有空白模板的ui:composition
给我一个页面错误。 只需删除整个标签<ui:composition></ui.composition>
即可开始。
另一条评论:JBoss 提供了一些快速入门示例,例如https://github.com/jboss-developer/jboss-eap-quickstarts/blob/7.1/numberguess ,可用作参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.