java.lang.NoClassDefFoundError:Tomcat中的jakarta/servlet/jsp/jstl/core/配置

voase2hg  于 2023-01-15  发布在  Java
关注(0)|答案(1)|浏览(153)

我阅读了其他帖子,他们指出将jstl依赖项添加到pom.xml中是可行的,然而,我尝试完全这样做,错误仍然存在:
完整的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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.1</version>
        <relativePath/>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>springmvctest</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>springmvctest</name>
    <description>springmvctest</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>

     

      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
      </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                          <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-tomcat</artifactId>
                          </exclusion>  
                </exclusions>                               
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
            <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我在Maven中遵循了干净的包过程,Spring Web应用程序启动完美,没有任何问题,但当我在控制器方法中返回视图名称时,它抛出错误:

我使用的是Tomcat 10.0.21和Spring。

o7jaxewo

o7jaxewo1#

pom.xml删除

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
      </dependency>

添加此

<dependency>
    <groupId>jakarta.servlet.jsp.jstl</groupId>
    <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
    <version>2.0.0</version>
</dependency>

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jakarta.servlet.jsp.jstl</artifactId>
    <version>2.0.0</version>
</dependency>

显示列表. jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSTL Test - Show List</title>
</head>

<body>
        <h1>JSTL Test</h1>
 
        <p>
            Show List:
            <ul>
                <c:forEach items="${list}" var="animal">
                    <li>${animal}</li>
                </c:forEach>        
            </ul>
        </p>

</body>
</html>

apache-tomcat-10.1.4下测试合格

相关问题