简体   繁体   English

Primefaces 和 Jboss 的 index.xhtml 404 错误

[英]index.xhtml 404 error with Primefaces and Jboss

I'm building a new Maven application with JBoss AS 7.1 , jsf 2.2 and Java7 .我正在使用JBoss AS 7.1jsf 2.2Java7构建一个新的 Maven 应用程序。 And no matter what, I cannot make it work.无论如何,我无法让它发挥作用。 The Jboss it's runnig well, I can see the welcome page but there is no way (I try a lot) to see the my index.xhtml page. Jboss 运行良好,我可以看到欢迎页面,但没有办法(我尝试了很多)看到我的index.xhtml页面。 It gives me an 404 error all the time.它一直给我一个404错误。

Here is my pom.xml :这是我的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>

This is my web.xml on the WEB-INF folder:这是我在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>

And this is my index.xhtml on my webapp folder:这是我的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>

Am I doing something wrong?难道我做错了什么? I think I tried everything... and now I'm stuck.我想我尝试了一切……现在我被卡住了。

Thank you in advance!先感谢您!

404 normally means page not found. 404 通常意味着找不到页面。 This suggests either the application isn't being deployed, or you're referencing the wrong name.这表明应用程序没有被部署,或者您引用了错误的名称。 Can you checked if the application is being deployed correctly, using the JBoss Admin Console?您能否使用 JBoss 管理控制台检查应用程序是否正确部署?

What I am missing from the POM is the maven-war-plugin , otherwise how are you creating the .war that needs to be deployed?我从 POM 中缺少的是maven-war-plugin ,否则你如何创建需要部署的 .war ?

In the web.xml file, you will need the <welcome-file-list> for index.xhtml (but not the others).在 web.xml 文件中,您将需要 index.xhtml 的<welcome-file-list> (而不是其他文件)。 Without it, the default initial page is index.html, but in Wildfly this gives me a "forbidden" error rather than a 404 if index.html doesn't exist.没有它,默认的初始页面是 index.html,但在 Wildfly 中,如果 index.html 不存在,这会给我一个“禁止”错误而不是 404。

In index.xhtml, the ui:composition with a blank template gives me a page error.在 index.xhtml 中,带有空白模板的ui:composition给我一个页面错误。 Just remove the whole tag <ui:composition></ui.composition> to get started.只需删除整个标签<ui:composition></ui.composition>即可开始。

One further comment: JBoss provide some quickstart examples such as https://github.com/jboss-developer/jboss-eap-quickstarts/blob/7.1/numberguess which are useful as a reference.另一条评论:JBoss 提供了一些快速入门示例,例如https://github.com/jboss-developer/jboss-eap-quickstarts/blob/7.1/numberguess ,可用作参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM