"JSF - HTTP Status 404 - Not Found" what can it be, even doing the suggested steps?

Asked

Viewed 253 times

-2

I’ve been programming for 32 years, but beginner in Java, so whoever votes negative, gentileza comenta o motivo... What may be obvious to you may be unattainable to others.

I started a web project with Maven + JPA/Hibernate + JSF + primefaces.

  • When opening (Tomcat) the index.xhtml file (localhost:8080/new-Hibernate-primefaces/index.xhtml), appear the created Labels, all in a single line, out of formatting..

  • Not even a hello world works (hello.xhtml, when I call hello.jsf)

  • Opening (Tomcat) the index.JSF file (localhost:8080/new-Hibernate-primefaces/index.jsf), causes the error below: Erro 404

ATTEMPTS:

  • I have tried several suggestions from here (en) and from stackoverflow.com, but none of the proposals worked. I’ve also checked the options in properties: "Right click on project", properties, Project Facets --> runtimes: mark: Apache Tomcat V9.0 and DESELECT JRE.

  • I have already deleted and re-configured Tomcat

  • Mark Dynamic Web Module 3.0

  • Select Java, Javascript, Javaserver Faces 2.2, JPA

  • I have also made a new project from scratch and the error persists.

  • An important detail is that, at the time, when I installed Eclipse, I had not marked the "Web Development" option. But now, I’ve added the Webtools packages (I think that’s it).

-Location of the archives: /new-Hibernate-primefaces/Webcontent/index.xhtml /new-Hibernate-primefaces/Webcontent/WEB-INF/faces-config.xml /new-Hibernate-primefaces/Webcontent/WEB-INF/web.xml /new-Hibernate-primefaces/pom.xml /new-Hibernate-primefaces/src/main/java/META-INF/persistence.xml

VERSIONS: Apache Tomcat: 9.0 Eclipse Version: 2020-09 (4.17.0) JDK 11.0.8 (NOT marked in the project, as recommended by the teacher)

Follows content from major files:

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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"> 

<h:body>
    <h:form>
    <h:panelGrid columns="2" cellpadding="5">       
        <h:outputLabel for="ident" Value="Id" />
        <h:inputText id="ident" readonly="true" value="#{usuarioPessoaManagedBean.usuarioPessoa.id}" />

        <h:outputLabel for="nome" Value="Nome" />
        <h:inputText id="nome" value="#{usuarioPessoaManagedBean.usuarioPessoa.nome}" />

        <h:outputLabel for="sobrenome" Value="Sobrenome" />
        <h:inputText id="sobrenome" value="#{usuarioPessoaManagedBean.usuarioPessoa.sobrenome}" />

        <h:outputLabel for="email" Value="Email" />
        <h:inputText id="email" value="#{usuarioPessoaManagedBean.usuarioPessoa.email}" />

        <h:outputLabel for="login" Value="Login" />
        <h:inputText id="login" value="#{usuarioPessoaManagedBean.usuarioPessoa.login}" />

        <h:outputLabel for="senha" Value="Senha" />
        <h:inputSecret id="senha" value="#{usuarioPessoaManagedBean.usuarioPessoa.senha}" />

        <h:outputLabel for="idade" Value="Idade" />
        <h:inputText id="idade" value="#{usuarioPessoaManagedBean.usuarioPessoa.idade}" />
    </h:panelGrid>
</h:form>
</h:body>

</html>

WEB.XML:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>new-hibernate-primefaces</display-name>
  <welcome-file-list>
       <welcome-file>index.jsf</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>
<session-config>
<session-timeout>5</session-timeout>
</session-config>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>            
<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>
</web-app>

FACES-CONFIG.XML:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
</faces-config>

POM.XML:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>new-hibernate-primefaces</groupId>
  <artifactId>new-hibernate-primefaces</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>new-hibernate-primefaces</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <!-- https://mvnrepository.com/artifact/javax.faces/jsf-api -->
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.20</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.20</version> <!-- Corrigido -->
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>8.0</version>
    </dependency>
      
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.22</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.4.22.Final</version>
    </dependency>    
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.4.22.Final</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

IMAGES THAT MAY BE USEFUL:

Java Build Path

Web Deployment Assembly

Project Facets #1

Project Facets #2

Project Facets #3

Java Server Faces - Library Configuration

Thank you!

1 answer

1

Dude, I had a similar problem with you using this version of JSF. When I returned to version 2.2.9 or 2.1.14 of JSF, the problem was quickly resolved. But looking at your code, I realized that the dependencies of Jsf api and impl are with different versions. Try to adjust for identical versions.

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
 
<!-- JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>

  • Thanks for the attention, @Tguitarful I think, from trying hard, I touched it and did not care to correct, but I did it and continues. http://localhost:8888/new-Hibernate-primefaces/index.jsf -> Error 404 http://localhost:8888/new-Hibernate-primefaces/index.xhtml -> Badly formatted fields

  • 1

    Dude, I didn’t see any success in version 2.3 of JSF, so much trying, I gave up. I created a pattern in using version 4.0 of the web and 2.2 of JSF and it went smoothly. I’ll take advantage while Tomcat still has support for both.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.