Jakarta EE:JSF 标签未转换为 HTML 标签

问题描述 投票:0回答:1

我已经在 IntelliJ Idea Ultimate (Maven) 中为 Java Enterprises 的大学项目设置了 Jakarta EE 项目,并且还可以在浏览器中输出 index.xhtml(通过 Tomcat 8.5.87)。我正在使用 Jakarta 9.1.0 和 Jakarta Faces 3.0.0。由于我对 Jakarta EE 完全没有经验,我想就 Tomcat 报告的以下错误寻求帮助:

**ERROR:**
03-Jan-2024 14:35:24.016 FEIN [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.util.Introspection.loadClass Konnte Klasse [jakarta.faces.webapp.FacesServlet] nicht laden
    java.lang.ClassNotFoundException: jakarta.faces.webapp.FacesServlet
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1420) [...]

以下是我需要审阅的最重要的文件:

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>demo</name>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.source>11</maven.compiler.source>
        <junit.version>5.9.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>9.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.mvc</groupId>
            <artifactId>jakarta.mvc-api</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>7.0.5.Final</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.faces</groupId>
            <artifactId>jakarta.faces-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
        </plugins>
    </build>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
         version="5.0">

    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>jakarta.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>

</web-app>

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="3.0" xmlns="https://jakarta.ee/xml/ns/jakartaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                                  https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd">

</faces-config>

index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

<h:head>
    <link rel="stylesheet" type="text/css" media="screen" href="style.css"/>
    <title>Login</title>
</h:head>

<h:body>
    <p><img id="kopf_links" src="logo.jpg" width="150" alt="Logo"/></p>
    <p id="kopf_rechts">
        <h:outputText value="TEST!"/>
        <br/>
        <h:outputText value="#{anschrift.name}"/>
        <br/>
        <h:outputText value="#{anschrift.strasse} #{anschrift.hausnummer}"/>
        <br/>
        <h:outputText value="#{anschrift.plz} #{anschrift.ort}"/>
    </p>
</h:body>

</html>

我已经多次尝试测试不同的依赖项(版本),多次重新启动服务器并遵循 IDE 的所有错误消息。

如果有任何可以解决问题的提示,我将不胜感激!

maven jsf jakarta-ee facelets
1个回答
0
投票

也许您的问题是 JSF 文件扩展名。

您的索引文件名为

index.xhtml
,但
servlet-mapping
中的 URL 模式设置为
*.jsf
文件扩展名。因此,它永远不会调用您的
FacesServlet

<url-pattern>*.jsf</url-pattern>

您需要将其映射到

<url-pattern>*.xhtml</url-pattern>

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.