java - Maven + JSTL 无法正常工作,所有配置均显示正常

标签 java maven jstl

错误如下:org.apache.jasper.JasperException:绝对 uri:http://java.sun.com/jsp/jSTL/core 无法在 web.xml 或 jar 文件中解析与此应用程序一起部署

我尝试了这篇文章How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved但没有任何作用:

我的文件:

web.xml

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

 <web-app version="2.5" 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_2_5.xsd">

  <display-name>ProjetoQuestoes</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-list>
</web-app>

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.dev-cheats.spring5</groupId>
    <artifactId>spring5-mvc-hibernate-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <spring.version>5.0.0.RELEASE</spring.version>
        <hibernate.version>5.2.11.Final</hibernate.version>
        <hibernate.validator>5.4.1.Final</hibernate.validator>
        <c3p0.version>0.9.5.2</c3p0.version>
        <jstl.version>1.2.1</jstl.version>
        <tld.version>1.1.2</tld.version>
        <servlets.version>3.1.0</servlets.version>
        <jsp.version>2.3.1</jsp.version>
        <hsqldb.version>1.8.0.10</hsqldb.version>
    </properties>
    <dependencies>
        <!-- Spring MVC Dependency -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Spring ORM -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Hibernate ORM -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Hibernate-C3P0 Integration -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- c3p0 -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>${c3p0.version}</version>
        </dependency>

        <!-- Hibernate Validator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator}</version>
        </dependency>

        <!-- JSTL Dependency -->
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>${jstl.version}</version>
        </dependency>

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>${tld.version}</version>
        </dependency>

        <!-- Servlet Dependency -->

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

        <!-- HSQL Dependency -->
        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>${hsqldb.version}</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- Embedded Apache Tomcat required for testing war -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

WEB-INF 文件夹中的 JSP:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
<link   type="text/css" href="resources/css/botao.css" rel="stylesheet" />
</head>

<body>
<iframe>
<form action="AdicionaQuestao">
  Questão<br/>
  <input type="text" name="questao" value="Insira aqui a questão"><br>
  <c:forEach var="i" begin="1" end="4">
      Opção<c:out value="${i}"/>:
       <input type="text" name="opcao<c:out value="${i}"/>" value="Insira aqui a opção">
            <br />
   </c:forEach>
  <input type="submit" value="Submit">
</form>
<!–– <button class="button">Black</button> -->
</iframe>

</body>
</html>

我没有看到任何使用 Maven 解决该问题的方法,我不想在 webapps 库中手动使用 JAR。

最佳答案

将以下依赖项添加到 pom.xml

             <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
            </dependency>

在jsp中导入以下uri。

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> 
OR 
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

关于java - Maven + JSTL 无法正常工作,所有配置均显示正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53563428/

相关文章:

java - 我应该如何覆盖 API 类的 equals 方法?

java - Java 中的继承是如何工作的?

java - OO设计-公共(public)API方法实现

java - Eclipse 上的向上箭头和数字含义

jsp - Tomcat开发模式下重新加载JSTL Tag文件

java - 如何定义一个类并将其实例创建为一个构造

java - Maven 编译 String.format 时出错

java - IDE 的 Maven 支持比带有 m2e 的 Eclipse 更好吗?

java - JSTL 标记内使用的 EL 表达式之前的“#”字符表现奇怪

java - Spring JasperException JSTL 标签